prevent unintended sign extension errors

When an unsigned char is shifted << 24 bits its type will be
promoted to signed 32-bits.   If the value is then assigned to
an unsigned 64-bit value sign extension will occur.

Prevent the unwanted sign extension by explicitly casting the
value to unsigned long before shifting.

Change-Id: Iabeac0f17dc3229a2dc89abe71960a8ffbf523f8
This commit is contained in:
Jeffrey Altman
2022-01-16 00:06:01 -05:00
committed by Jeffrey Altman
parent 3707c52ea7
commit f341fa7721
6 changed files with 10 additions and 7 deletions

View File

@@ -69,8 +69,9 @@ data_hash(void *ptr)
if (os->length < 4)
return os->length;
return s[0] | (s[1] << 8) |
(s[os->length - 2] << 16) | (s[os->length - 1] << 24);
return ((unsigned long)s[os->length - 1] << 24)
| (s[os->length - 2] << 16) | (s[1] << 8) | s[0];
}
struct heim_type_data _heim_data_object = {