diff options
author | dkf <dkf@noemail.net> | 2007-01-22 09:15:49 (GMT) |
---|---|---|
committer | dkf <dkf@noemail.net> | 2007-01-22 09:15:49 (GMT) |
commit | 5268561fde5e97c6f0ecdcd53c1a634d52c47cb2 (patch) | |
tree | 1ed33dbdc04db399d15477819412a5cfdc8f05b1 | |
parent | cabed0bbb27ef874dd97a8b659740a881775d834 (diff) | |
download | tcl-5268561fde5e97c6f0ecdcd53c1a634d52c47cb2.zip tcl-5268561fde5e97c6f0ecdcd53c1a634d52c47cb2.tar.gz tcl-5268561fde5e97c6f0ecdcd53c1a634d52c47cb2.tar.bz2 |
Fix [Bug 1631017]
FossilOrigin-Name: 5e8c416d24b19526e27ac2358d41835498b1ca58
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | compat/memcmp.c | 50 |
2 files changed, 33 insertions, 22 deletions
@@ -1,3 +1,8 @@ +2007-01-22 Donal K. Fellows <donal.k.fellows@manchester.ac.uk> + + * compat/memcmp.c (memcmp): Reworked so that arithmetic is never + performed upon void pointers, since that is illegal. [Bug 1631017] + 2007-01-19 Donal K. Fellows <donal.k.fellows@man.ac.uk> * generic/tclCompile.c (TclCompileScript): Reduce the frequency with diff --git a/compat/memcmp.c b/compat/memcmp.c index 68e18c5..43202a5 100644 --- a/compat/memcmp.c +++ b/compat/memcmp.c @@ -1,25 +1,23 @@ -/* +/* * memcmp.c -- * * Source code for the "memcmp" library routine. * * Copyright (c) 1998 Sun Microsystems, Inc. * - * See the file "license.terms" for information on usage and redistribution - * of this file, and for a DISCLAIMER OF ALL WARRANTIES. + * See the file "license.terms" for information on usage and redistribution of + * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * SCCS: @(#) memcmp.c 1.2 98/01/19 10:48:58 + * RCS: @(#) $Id: memcmp.c,v 1.4 2007/01/22 09:15:50 dkf Exp $ */ #include "tclPort.h" /* - * Here is the prototype just in case it is not included - * in tclPort.h. + * Here is the prototype just in case it is not included in tclPort.h. */ -int memcmp _ANSI_ARGS_((CONST VOID *s1, - CONST VOID *s2, size_t n)); +int memcmp(CONST VOID *s1, CONST VOID *s2, size_t n); /* *---------------------------------------------------------------------- @@ -29,11 +27,10 @@ int memcmp _ANSI_ARGS_((CONST VOID *s1, * Compares two bytes sequences. * * Results: - * compares its arguments, looking at the first n - * bytes (each interpreted as an unsigned char), and returns - * an integer less than, equal to, or greater than 0, accord- - * ing as s1 is less than, equal to, or - * greater than s2 when taken to be unsigned 8 bit numbers. + * Compares its arguments, looking at the first n bytes (each interpreted + * as an unsigned char), and returns an integer less than, equal to, or + * greater than 0, according as s1 is less than, equal to, or greater + * than s2 when taken to be unsigned 8 bit numbers. * * Side effects: * None. @@ -42,19 +39,28 @@ int memcmp _ANSI_ARGS_((CONST VOID *s1, */ int -memcmp(s1, s2, n) - CONST VOID *s1; /* First string. */ - CONST VOID *s2; /* Second string. */ - size_t n; /* Length to compare. */ +memcmp( + CONST VOID *s1, /* First string. */ + CONST VOID *s2, /* Second string. */ + size_t n) /* Length to compare. */ { - unsigned char u1, u2; + CONST unsigned char *ptr1 = (CONST unsigned char *) s1; + CONST unsigned char *ptr2 = (CONST unsigned char *) s2; + + for ( ; n-- ; ptr1++, ptr2++) { + unsigned char u1 = *ptr1, u2 = *ptr2; - for ( ; n-- ; s1++, s2++) { - u1 = * (unsigned char *) s1; - u2 = * (unsigned char *) s2; - if ( u1 != u2) { + if (u1 != u2) { return (u1-u2); } } return 0; } + +/* + * Local Variables: + * mode: c + * c-basic-offset: 4 + * fill-column: 78 + * End: + */ |