Skip to content

Commit

Permalink
Fix address sanitizer issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jwijffels committed Oct 21, 2018
1 parent 00282aa commit dffa922
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

- Fix for as.crf when loaded from file and adding more arguments than just the file
- added txt_feature as a simple feature extraction to identify if a word is capitalised, an email, an url or a number
- src/cqdb/src/lookup3.c, fix address sanitizer issue

# CHANGES IN crfsuite VERSION 0.1.1

Expand Down
47 changes: 25 additions & 22 deletions src/cqdb/src/lookup3.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,27 +312,30 @@ uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
* still catch it and complain. The masking trick does make the hash
* noticably faster for short strings (like English words).
*/
#ifndef VALGRIND

switch(length)
{
case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
case 8 : b+=k[1]; a+=k[0]; break;
case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
case 6 : b+=k[1]&0xffff; a+=k[0]; break;
case 5 : b+=k[1]&0xff; a+=k[0]; break;
case 4 : a+=k[0]; break;
case 3 : a+=k[0]&0xffffff; break;
case 2 : a+=k[0]&0xffff; break;
case 1 : a+=k[0]&0xff; break;
case 0 : return c; /* zero length strings require no mixing */
}

#else /* make valgrind happy */

//#ifndef VALGRIND
//
// switch(length)
// {
// case 12: c+=k[2]; b+=k[1]; a+=k[0]; break;
// case 11: c+=k[2]&0xffffff; b+=k[1]; a+=k[0]; break;
// case 10: c+=k[2]&0xffff; b+=k[1]; a+=k[0]; break;
// case 9 : c+=k[2]&0xff; b+=k[1]; a+=k[0]; break;
// case 8 : b+=k[1]; a+=k[0]; break;
// case 7 : b+=k[1]&0xffffff; a+=k[0]; break;
// case 6 : b+=k[1]&0xffff; a+=k[0]; break;
// case 5 : b+=k[1]&0xff; a+=k[0]; break;
// case 4 : a+=k[0]; break;
// case 3 : a+=k[0]&0xffffff; break;
// case 2 : a+=k[0]&0xffff; break;
// case 1 : a+=k[0]&0xff; break;
// case 0 : return c; /* zero length strings require no mixing */
// }
//
//#else /* make valgrind happy */

// ADDED TO FIX R CMD CHECK ADDRESSSANITIZER ISSUE
const uint8_t* k8;

k8 = (const uint8_t *)k;
switch(length)
{
Expand All @@ -351,7 +354,7 @@ uint32_t hashlittle( const void *key, size_t length, uint32_t initval)
case 0 : return c;
}

#endif /* !valgrind */
//#endif /* !valgrind */

} else if (HASH_LITTLE_ENDIAN && ((u.i & 0x1) == 0)) {
const uint16_t *k = (const uint16_t *)key; /* read 16-bit chunks */
Expand Down

0 comments on commit dffa922

Please sign in to comment.