Commit Graph

32 Commits

Author SHA1 Message Date
Conrad Meyer
41bd31e656 expr(1): Fix overflow detection when operand is INTMAX_MIN
PR:		227329
Submitted by:	Tobias Stoeckmann <tobias AT stoeckmann.org>
2018-04-14 04:35:10 +00:00
Stefan Eßer
8da97f0057 Fix overflow check for multiplication:
- Add special test to detect the case of -1 * INTMAX_MIN
- Protect against elimination of the test division by the optimizer

Garrett Cooper noticed that the overflow checks were incomplete, and Bruce
Evans suggested the use of the "volatile" qualifier to counter the effect
of the undefined behaviour, when the prior multiplication caused overflow,
and he also suggested improvements to the comments.

Reviewed by:	bde
MFC after:	1 week
2015-01-27 18:04:41 +00:00
Kevin Lo
fcae0e3887 Remove redundant declaration of yyparse
Reported by:	tinderbox
2012-05-22 03:01:54 +00:00
Eitan Adler
8c3bbba824 rm[0].rm_so must be zero (an explicit check is made for zero in the
outer if condition)

Reviewed by:	se
Approved by:	cperciva
2012-03-19 00:45:01 +00:00
Stefan Eßer
69759f0829 Fix style, since this file has just been touched in a major way.
No actual code changes.
2011-07-09 12:20:15 +00:00
Stefan Eßer
6fbe7bf4f2 Some refactoring for easier maintenance of the code. This is a follow-up
to re-establishment of 64bit arithmetic, but is committed separately, to
not obscure that conversion. This commit does not change the observed
behaviour of expr in any way. Style will be fixed in a follow-up commit.
2011-07-09 12:14:57 +00:00
Stefan Eßer
fa717604a4 Make /bin/expr support 64bit numeric range and range checks by default,
again. This brings back the behaviour of expr in FreeBSD-4, which had been
reverted due to an assumed incompatbility with POSIX.1 for FreeBSD-5.

This issue has been discussed in the freebsd-standards list, and the
consensus was, that POSIX.1 is in fact not violated by this extension,
since it affects only cases of POSIX undefined behaviour (overflow of
signed long).

Other operating systems did upgrade their versions of expr to support
64bit range, after it had been initially brought to FreeBSD. They have
used it for a decade without problems, meanwhile.

The -e option is retained, but it will only select less strict checking
of numeric parameters (leading white-space, leading "+" are allowed and
skipped, an empty string is considered to represent 0 in numeric context.)
The call of check_utility_compat() as a means of establishing backwards
compatibility with FreeBSD-4 is considered obsolete, but preserved in
this commit. It is expected to be removed in a later revision of this
file.
Reviewed by:	bde, das, jilles
MFC after:	2 month (those parts that do not violate POLA)
2011-07-09 12:05:53 +00:00
Ceri Davies
e1854a84ad Correct typos containing my login name (plus one more in expr.y).
Found courtesy of a recursive grep in the wrong directory.
2007-02-18 19:48:59 +00:00
Warner Losh
9ddb49cbe4 /*- or .\"- or #- to begin license clauses. 2005-01-10 08:39:26 +00:00
Garrett Wollman
c9885518de Create a small library function, check_utility_compat(3), to determine
whether a named utility should behave in FreeBSD 4.x-compatible mode
or in a standard mode (default standard).  The configuration is done
malloc(3)-style, with either an environment variable or a symlink.

Update expr(1) to use this new interface.
2002-10-28 00:15:43 +00:00
Garrett Wollman
94a48596a3 EXPR_COMPAT should imply -e, since there is no way to specify it otherwise,
and -e reflects the historic behavior of FreeBSD's expr.
2002-05-11 03:08:12 +00:00
Garrett Wollman
1393277e29 The response to my POSIX interpretation request says that `expr'
is required to be oblivious to overflow and to use the data type `long'.
(Division by zero is undefined in ISO C so it's still OK to check for it
here.)  Add a new `-e' flag to get the old, more useful behavior.
2002-05-10 22:59:29 +00:00
Garrett Wollman
96ab7da385 Provide an environment variabloe, EXPR_COMPAT, which disables option
parsing for compatibility with old implementations.
2002-04-22 21:23:09 +00:00
Garrett Wollman
f07e42470f Make expr POSIX-compliant, and fix some bugs. Specifically:
- expr must conform to the Utility Syntax Guidelines, so use
getopt() to eat the (non-existent) options.

- Use the Standard type intmax_t for arithmetic.

- If an argument cannot be *completely* converted to an integer, then
it is a string.

Additionally make some style cleanups near the modified lines.  This
utility is still not completely style-compliant.
2002-03-22 20:18:26 +00:00
Warner Losh
7669d0fc4f o __P has been reoved
o Old-style K&R declarations have been converted to new C89 style
o register has been removed
o prototype for main() has been removed (gcc3 makes it an error)
o int main(int argc, char *argv[]) is the preferred main definition.
o Attempt to not break style(9) conformance for declarations more than
  they already are.
o gc some #ifdef sun ... #endif code

Approved by: arch@, new style(9)
2002-02-02 06:36:49 +00:00
Kris Kennaway
3d06e95d35 Fix warnings to compile with WARNS=2 on i386 and alpha
Reviewed by:	bde
2001-05-26 20:45:25 +00:00
Stefan Eßer
915198b41b Add overflow tests 2000-07-22 10:59:36 +00:00
Stefan Eßer
64867286e5 Extend numeric operations to support 64 bit numbers. 2000-07-10 21:30:55 +00:00
Peter Wemm
2a4562393f $Id$ -> $FreeBSD$ 1999-08-27 23:15:48 +00:00
Peter Wemm
b97fa2ef50 Revert $FreeBSD$ to $Id$ 1997-02-22 14:13:04 +00:00
Jordan K. Hubbard
1130b656e5 Make the long-awaited change from $Id$ to $FreeBSD$
This will make a number of things easier in the future, as well as (finally!)
avoiding the Id-smashing problem which has plagued developers for so long.

Boy, I'm glad we're not using sup anymore.  This update would have been
insane otherwise.
1997-01-14 07:20:47 +00:00
Joerg Wunsch
717252ea98 Fix my own brokeness for the colon operator, when one of the arguments
was a valid integer.  The actual decision between integer and string
is now context-dependant on the operator being used.
1995-11-18 18:05:03 +00:00
Joerg Wunsch
2a353a9fb4 expr(1) didn't comply to Posix.2 and its own man page: any
comparisions have been made as string comparisions, even in cases
where both operands clearly qualified as integers.

The fix is to make the parser properly analyzing whether an operand is
a valid integer or not.
1995-08-04 17:08:07 +00:00
Joerg Wunsch
0fd510b71a You will find enclosed some changes to make gcc -Wall more happy in
/usr/src/bin. Note that some patches are still needed in that directory.

I (Joerg) finished most of Philippe's cleanup.  /bin/sh will still
need *allot* of work, however.

Submitted by:	charnier@lirmm.fr (Philippe Charnier)
1995-03-19 13:29:28 +00:00
David Greenman
89730b290a Added $Id$ 1994-09-24 02:59:15 +00:00
Bruce Evans
395b07d1df Explicitly include <sys/types.h> before including <regex.h>. This is
apparently required by POSIX.  It will be required in practice when
the bogus inclusion of <sys/types.h> is removed from <stdio.h>.
1994-09-05 13:03:50 +00:00
J.T. Conklin
4a13ab7c12 Allow expressions like "expr 'ABC' : '^.*$' to work as is done in other
expr implementations.
1993-10-04 21:58:53 +00:00
J.T. Conklin
4cf61aba29 Fix grammar to eliminate support for unary minus expressions -- they
weren't supported, they aren't standard, and they caused expr to dump
core.
1993-09-14 22:49:52 +00:00
J.T. Conklin
55c497bf15 1003.2 requires that lexical comparisons be done in locale specific manner,
so we have to use strcoll() instead of strcmp().
1003.2 requires that a null string be returned if a string does not match
a \( \) subexpression.
Replaced fprintf/exit with calls to err and errx as appropriate.
1993-08-17 16:06:00 +00:00
J.T. Conklin
c9fe00dc0b Update to my latest expr (fixes bugs with comparison and matching operators)
Add man page I wrote.
1993-07-21 22:56:14 +00:00
Andrew Moore
4ba5f2985d added POSIX regex to expr 1993-06-19 01:55:46 +00:00
Rodney W. Grimes
5b81b6b301 Initial import, 0.1 + pk 0.2.4-B1 1993-06-12 14:58:17 +00:00