Skip to content

Commit e823bf2

Browse files
peterhillmancary-ilm
authored andcommitted
Fix AcademySoftwareFoundation#713: cast to unsigned in testHuf checksum (AcademySoftwareFoundation#717)
* cast to unsigned in testHuf checksum to avoid architectures sign extending differently Signed-off-by: Peter Hillman <[email protected]>
1 parent 5670325 commit e823bf2

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

OpenEXR/IlmImfTest/testHuf.cpp

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ compressUncompressSubset(const unsigned short raw[], int n)
181181
// This DEK hash is determined from an aprior initial run of this
182182
// test noting its value from the assert message compressVerify().
183183
//
184-
#define HUF_COMPRESS_DEK_HASH_FOR_FILL4_USHRT_MAX_PLUS_ONE 2956869585U
185-
#define HUF_COMPRESS_DEK_HASH_FOR_FILL4_N 3414126535U
186-
#define HUF_COMPRESS_DEK_HASH_FOR_FILL5_N 169791374U
184+
#define HUF_COMPRESS_DEK_HASH_FOR_FILL4_USHRT_MAX_PLUS_ONE 2013380646U
185+
#define HUF_COMPRESS_DEK_HASH_FOR_FILL4_N 213880353U
186+
#define HUF_COMPRESS_DEK_HASH_FOR_FILL5_N 2492982090U
187187

188188
void
189189
compressVerify (const unsigned short raw[],
@@ -200,7 +200,7 @@ compressVerify (const unsigned short raw[],
200200
// under the topic of sorting and search chapter 6.4.
201201
//
202202
unsigned int compressedHash = nCompressed;
203-
const char* cptr = compressed;
203+
const unsigned char* cptr = reinterpret_cast<const unsigned char*>( (const char*) compressed);
204204
for (int i = 0; i < nCompressed; ++i)
205205
{
206206
compressedHash =
@@ -210,6 +210,25 @@ compressVerify (const unsigned short raw[],
210210
cout << "verifying compressed checksum hash = "
211211
<< compressedHash << std::endl;
212212

213+
if (compressedHash != dekHash)
214+
{
215+
cout << "hash verification failed. Got " << compressedHash << " expected " << dekHash << std::endl;
216+
const unsigned char* cptr = reinterpret_cast<const unsigned char*>( (const char*) compressed);
217+
for(int i = 0 ; i < nCompressed ; ++i )
218+
{
219+
cout << std::hex << (0xFF & (int) (*cptr++));
220+
if ( (i & 0xF) ==0 )
221+
{
222+
cout << '\n';
223+
}
224+
else
225+
{
226+
cout << ' ';
227+
}
228+
}
229+
cout << "\n";
230+
}
231+
213232
assert (compressedHash == dekHash);
214233
}
215234

0 commit comments

Comments
 (0)