diff options
| author | Paul Eggert | 2011-07-27 17:48:01 -0700 |
|---|---|---|
| committer | Paul Eggert | 2011-07-27 17:48:01 -0700 |
| commit | 044c22e545acef592ed95e4e3bb9f8aeff67291a (patch) | |
| tree | 167a4c706b62b12ea979bdf6ad47e70b66bb0394 /src/fns.c | |
| parent | dbf38e02c9ade4979418f24a99962cfef170b957 (diff) | |
| parent | 8265d3bb30544e58683fc16e23f9908f3d5d0abc (diff) | |
| download | emacs-044c22e545acef592ed95e4e3bb9f8aeff67291a.tar.gz emacs-044c22e545acef592ed95e4e3bb9f8aeff67291a.zip | |
Merge: Integer signedness and overflow and related fixes.
Fixes: debbugs:9079
Diffstat (limited to 'src/fns.c')
| -rw-r--r-- | src/fns.c | 26 |
1 files changed, 17 insertions, 9 deletions
| @@ -4098,25 +4098,33 @@ sweep_weak_hash_tables (void) | |||
| 4098 | #define SXHASH_REDUCE(X) \ | 4098 | #define SXHASH_REDUCE(X) \ |
| 4099 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) | 4099 | ((((X) ^ (X) >> (BITS_PER_EMACS_INT - FIXNUM_BITS))) & INTMASK) |
| 4100 | 4100 | ||
| 4101 | /* Return a hash for string PTR which has length LEN. The hash | 4101 | /* Return a hash for string PTR which has length LEN. The hash value |
| 4102 | code returned is guaranteed to fit in a Lisp integer. */ | 4102 | can be any EMACS_UINT value. */ |
| 4103 | 4103 | ||
| 4104 | static EMACS_UINT | 4104 | EMACS_UINT |
| 4105 | sxhash_string (unsigned char *ptr, EMACS_INT len) | 4105 | hash_string (char const *ptr, ptrdiff_t len) |
| 4106 | { | 4106 | { |
| 4107 | unsigned char *p = ptr; | 4107 | char const *p = ptr; |
| 4108 | unsigned char *end = p + len; | 4108 | char const *end = p + len; |
| 4109 | unsigned char c; | 4109 | unsigned char c; |
| 4110 | EMACS_UINT hash = 0; | 4110 | EMACS_UINT hash = 0; |
| 4111 | 4111 | ||
| 4112 | while (p != end) | 4112 | while (p != end) |
| 4113 | { | 4113 | { |
| 4114 | c = *p++; | 4114 | c = *p++; |
| 4115 | if (c >= 0140) | ||
| 4116 | c -= 40; | ||
| 4117 | hash = SXHASH_COMBINE (hash, c); | 4115 | hash = SXHASH_COMBINE (hash, c); |
| 4118 | } | 4116 | } |
| 4119 | 4117 | ||
| 4118 | return hash; | ||
| 4119 | } | ||
| 4120 | |||
| 4121 | /* Return a hash for string PTR which has length LEN. The hash | ||
| 4122 | code returned is guaranteed to fit in a Lisp integer. */ | ||
| 4123 | |||
| 4124 | static EMACS_UINT | ||
| 4125 | sxhash_string (char const *ptr, ptrdiff_t len) | ||
| 4126 | { | ||
| 4127 | EMACS_UINT hash = hash_string (ptr, len); | ||
| 4120 | return SXHASH_REDUCE (hash); | 4128 | return SXHASH_REDUCE (hash); |
| 4121 | } | 4129 | } |
| 4122 | 4130 | ||
| @@ -4231,7 +4239,7 @@ sxhash (Lisp_Object obj, int depth) | |||
| 4231 | /* Fall through. */ | 4239 | /* Fall through. */ |
| 4232 | 4240 | ||
| 4233 | case Lisp_String: | 4241 | case Lisp_String: |
| 4234 | hash = sxhash_string (SDATA (obj), SCHARS (obj)); | 4242 | hash = sxhash_string (SSDATA (obj), SBYTES (obj)); |
| 4235 | break; | 4243 | break; |
| 4236 | 4244 | ||
| 4237 | /* This can be everything from a vector to an overlay. */ | 4245 | /* This can be everything from a vector to an overlay. */ |