| Commit message (Collapse) | Author | Age | Files | Lines | |
|---|---|---|---|---|---|
| * | rc: avoid undefined C | Xi Wang | 2013-03-19 | 1 | -4/+4 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There are two bugs in pdec() on INT_MIN: * wrong output. `n = 1-n' should be `n = -1-n' when n is INT_MIN. * infinite loop. gcc optimizes `if(n>=0)' into `if(true)' because `-INT_MIN' (signed integer overflow) is undefined behavior in C, and gcc assumes the negation of a negative number must be positive. The resulting binary keeps printing '-' forever given INT_MIN. Try the simplified pdec.c below. $ gcc pdec.c $ ./a.out -2147483648 --214748364* $ gcc pdec.c -O2 $ ./a.out -2147483648 <infinite loop> $ gcc pdec.c -O2 -D__PATCH__ $ ./a.out -2147483648 -2147483648 === pdec.c === #include <stdio.h> #include <stdlib.h> #include <limits.h> #define io void void pchr(io *f, int c) { putchar(c); } void pdec(io *f, int n) { if(n<0){ #ifndef __PATCH__ n=-n; if(n>=0){ pchr(f, '-'); pdec(f, n); return; } /* n is two's complement minimum integer */ n = 1-n; #else if(n!=INT_MIN){ pchr(f, '-'); pdec(f, -n); return; } /* n is two's complement minimum integer */ n = -(INT_MIN+1); #endif pchr(f, '-'); pdec(f, n/10); pchr(f, n%10+'1'); return; } if(n>9) pdec(f, n/10); pchr(f, n%10+'0'); } int main(int argc, char **argv) { int n = atoi(argv[1]); pdec(NULL, n); putchar('\n'); } R=rsc CC=plan9port.codebot https://codereview.appspot.com/7241055 | ||||
| * | rc: silence lion roar | Russ Cox | 2011-08-02 | 1 | -0/+1 |
| | | | | | | R=rsc http://codereview.appspot.com/4835048 | ||||
| * | rc: fix $ifs bug introduced with utf-8 code | Russ Cox | 2011-02-16 | 1 | -2/+4 |
| | | | | | | R=rsc http://codereview.appspot.com/4187050 | ||||
| * | rc: handle 4-byte utf-8 | Russ Cox | 2011-01-02 | 3 | -0/+20 |
| | | | | | | R=rsc http://codereview.appspot.com/3833043 | ||||
| * | rc: handle utf-8 in $ifs | Russ Cox | 2011-01-02 | 1 | -8/+16 |
| | | | | | | R=rsc http://codereview.appspot.com/3798046 | ||||
| * | rc: implement and document <>{cmd} notation | Michael Teichgräber | 2009-09-13 | 1 | -17/+47 |
| | | | | | http://codereview.appspot.com/105061 | ||||
| * | rc: make read not ignore interrupts/errors (again) | Michael Teichgräber | 2009-08-23 | 1 | -2/+7 |
| | | | | | http://codereview.appspot.com/110042 | ||||
| * | rc: fix segfault when SIGINT is received | Michael Teichgräber | 2009-08-08 | 1 | -1/+2 |
| | | | | | | | | | | | | | Save the value of `runq' at the start of the function, so that the `pc' update at the end does work on that original value, and not on a probably modified value of `runq'. fixes #14 http://code.swtch.com/plan9port/issue/14/ http://codereview.appspot.com/104066 | ||||
| * | rc: fix local variables in functions | Russ Cox | 2008-08-14 | 2 | -4/+4 |
| | | | | | | | | reported by micah stetson: fn foo { echo $bar } bar=baz foo | ||||
| * | rc: add subscript sequences (Erik Quanstrom) | Russ Cox | 2008-07-20 | 1 | -5/+35 |
| | | |||||
| * | keep path and PATH in sync | rsc | 2007-03-28 | 1 | -0/+2 |
| | | |||||
| * | do not redefine rewind | rsc | 2007-03-26 | 1 | -1/+1 |
| | | |||||
| * | more memory errors (valgrind) | rsc | 2007-03-26 | 3 | -1/+3 |
| | | |||||
| * | fix wait | rsc | 2007-03-26 | 5 | -251/+97 |
| | | |||||
| * | fix phantom rc crashes | rsc | 2007-03-26 | 1 | -0/+1 |
| | | |||||
| * | sync with plan 9 | rsc | 2007-03-26 | 23 | -1232/+1967 |
| | | |||||
| * | cope with programs that leave fd in non-blocking mode (Tim Wiess) | rsc | 2007-03-25 | 2 | -1/+27 |
| | | |||||
| * | experiment - allow = in words late in the command line | rsc | 2006-06-27 | 1 | -0/+3 |
| | | |||||
| * | add exitcode | rsc | 2006-04-08 | 1 | -0/+11 |
| | | |||||
| * | Use gcc -ansi -pedantic in 9c. Fix many non-C89-isms. | rsc | 2006-04-01 | 2 | -3/+3 |
| | | |||||
| * | update lucida | rsc | 2006-03-20 | 1 | -1/+1 |
| | | |||||
| * | shut up about signals in scripts | rsc | 2006-02-14 | 1 | -1/+1 |
| | | |||||
| * | Add rfork builtin. | rsc | 2005-08-11 | 1 | -0/+53 |
| | | |||||
| * | make sure errors cause non-zero exit status | rsc | 2005-08-11 | 1 | -0/+2 |
| | | |||||
| * | fixes from bengt for sun | rsc | 2005-07-26 | 1 | -2/+2 |
| | | |||||
| * | ignore window size change | rsc | 2005-07-14 | 1 | -0/+1 |
| | | |||||
| * | stupid sun | rsc | 2005-07-13 | 1 | -0/+3 |
| | | |||||
| * | set $PLAN9 if necessary | rsc | 2005-05-19 | 1 | -0/+3 |
| | | |||||
| * | try harder to put background jobs in background; do not print in response to ↵ | rsc | 2005-03-18 | 4 | -1/+45 |
| | | | | | SIGPIPE | ||||
| * | correct command-printing bug | rsc | 2005-03-18 | 1 | -1/+3 |
| | | |||||
| * | handle /dev/stdin always | rsc | 2005-02-13 | 2 | -3/+3 |
| | | |||||
| * | set pid=-1 explicitly | rsc | 2005-02-11 | 1 | -0/+1 |
| | | |||||
| * | more searchpath-related changes | rsc | 2005-01-23 | 2 | -1/+2 |
| | | |||||
| * | use correct yacc | rsc | 2005-01-19 | 1 | -1/+0 |
| | | |||||
| * | Many small edits. | rsc | 2005-01-13 | 1 | -0/+1 |
| | | |||||
| * | maintain $path and $PATH simultaneously | rsc | 2005-01-12 | 5 | -4/+74 |
| | | |||||
| * | success on the sun | rsc | 2005-01-07 | 1 | -0/+16 |
| | | |||||
| * | FreeBSD tweaks | rsc | 2004-12-28 | 1 | -4/+2 |
| | | |||||
| * | print out signalled exits | rsc | 2004-10-17 | 1 | -0/+5 |
| | | |||||
| * | add ulimit and umask as builtins | rsc | 2004-10-17 | 3 | -0/+202 |
| | | |||||
| * | Supress line noise. | wkj | 2004-05-16 | 1 | -0/+3 |
| | | |||||
| * | More little bug fixes | rsc | 2004-05-14 | 1 | -1/+0 |
| | | |||||
| * | Fix small bugs. | rsc | 2004-05-11 | 1 | -1/+1 |
| | | |||||
| * | Little fixes. | rsc | 2004-04-30 | 1 | -0/+1 |
| | | |||||
| * | fix | rsc | 2004-04-24 | 1 | -1/+0 |
| | | |||||
| * | Add scat. Temporary fix to rc r.e. note groups. | rsc | 2004-04-24 | 1 | -1/+1 |
| | | |||||
| * | clean up when finished. | rsc | 2004-04-19 | 1 | -1/+0 |
| | | | | | | don't set PLAN9 don't set PLAN9 | ||||
| * | handle interrupts and backgrounded processes a little better. | rsc | 2004-03-26 | 3 | -1/+11 |
| | | |||||
| * | SunOS can rot in hell. | rsc | 2004-03-26 | 1 | -4/+3 |
| | | |||||
| * | Today's changes. | rsc | 2004-03-25 | 1 | -12/+2 |
| | | | | | More changes. | ||||
