[hackers] [sbase][PATCH 0/2] expr: fix handling of strings in matching commands

2024-01-07 Thread Randy Palamar
Hi! Currently 'expr' always tries to evaluate its arguments as numbers even when the operation performed will require strings. This leads to couple different bugs reported on [dev][0]. First: `expr 3 : '.*'` should evaluate to the length of the string but currently it evaluates to 1. Second:

[hackers] [sbase][PATCH 1/2] expr: treat expressions as strs until evaluation

2024-01-07 Thread Randy Palamar
Comparison operations (>, <, =, etc.) and matching operations must operate originally provided string not one that has gone back and forth through string formatting. This caused operations such as the following to give incorrect results: ./expr 3 : '.*' Before: 1 After: 5 This commit fixes th

[hackers] [sbase][PATCH 2/2] expr: don't evaluate matched substr as a number

2024-01-07 Thread Randy Palamar
POSIX specifies that if the pattern contains a subexpression then the first matched subexpression should be returned if it exists. This fixes things like the following: ./expr 3 : '\(.*\)' Before: 3 After: 3 --- expr.c | 13 ++--- 1 file changed, 2 insertions(+), 11 deletions(-)