plan9port/src/libsec
Xi Wang 8a2a5b8f25 libsec: avoid undefined C
gcc compiles `p + length < p' into 'length < 0' since pointer overflow is undefined behavior in C.  This breaks the check against a large `length'.

Use `length > pend - p' instead.

There's no need to check `length < 0' since `length' is from length_decode() and should be non-negative.

===

Try the simplified code.

void bar(void);
void foo(unsigned char *p, int length)
{
        if (p + length < p)
                bar();
}

$ gcc -S -o - t.c -O2
...
foo:
.LFB0:
        .cfi_startproc
        testl	%esi, %esi
        js	.L4
        rep
        ret
.L4:
        jmp	bar
        .cfi_endproc

Clearly `p' is not used at all.

R=rsc
CC=plan9port.codebot
https://codereview.appspot.com/7231069
2013-03-19 14:35:16 -04:00
..
386 SunOS fixes (thanks Aram Hăvărneanu) 2011-05-17 18:48:42 -04:00
PowerMacintosh Empty changelog 2004-05-14 23:13:34 +00:00
arm arm: build fixes 2011-05-18 13:20:56 -04:00
port libsec: avoid undefined C 2013-03-19 14:35:16 -04:00
power ditto 2004-04-21 05:43:24 +00:00
sparc64 sparc 2006-02-09 08:17:49 +00:00
sun4u Empty changelog 2004-05-14 23:13:34 +00:00
x86_64 continue x86-64 2005-01-19 04:05:19 +00:00
mkfile make scripts work with more shells, 2004-04-21 05:49:52 +00:00