@@ -370,13 +370,13 @@ void SBF::SaveToDisk(std::string path, int mode)
370
370
// int area the area label
371
371
void SBF::Insert (char *string, int size, int area)
372
372
{
373
- char buffer[size];
373
+ char * buffer = new char [size];
374
374
375
375
// We allow a maximum SBF mapping of 32 bit (resulting in 2^32 cells).
376
376
// Thus, the hash digest is limited to the first four bytes.
377
377
unsigned char digest32[SBF::MAX_BYTE_MAPPING];
378
378
379
- unsigned char digest[this ->HASH_digest_length ];
379
+ unsigned char * digest = new unsigned char [this ->HASH_digest_length ];
380
380
381
381
// Computes the hash digest of the input 'HASH_number' times; each
382
382
// iteration combines the input char array with a different hash salt
@@ -386,7 +386,7 @@ void SBF::Insert(char *string, int size, int area)
386
386
buffer[j] = (char )(string[j]^this ->HASH_salt [k][j]);
387
387
}
388
388
389
- this ->Hash (buffer, size, (unsigned char *)& digest);
389
+ this ->Hash (buffer, size, (unsigned char *)digest);
390
390
391
391
// Truncates the digest after the first 32 bits (see above)
392
392
for (int i = 0 ; i < SBF::MAX_BYTE_MAPPING; i++){
@@ -408,6 +408,8 @@ void SBF::Insert(char *string, int size, int area)
408
408
this ->members ++;
409
409
this ->AREA_members [area]++;
410
410
411
+ delete[] buffer;
412
+ delete[] digest;
411
413
}
412
414
413
415
// Verifies weather the input element belongs to one of the mapped sets.
@@ -417,15 +419,15 @@ void SBF::Insert(char *string, int size, int area)
417
419
// int size length of the element
418
420
int SBF::Check (char *string, int size)
419
421
{
420
- char buffer[size];
422
+ char * buffer = new char [size];
421
423
int area = 0 ;
422
424
int current_area = 0 ;
423
425
424
426
// We allow a maximum SBF mapping of 32 bit (resulting in 2^32 cells).
425
427
// Thus, the hash digest is limited to the first four bytes.
426
428
unsigned char digest32[SBF::MAX_BYTE_MAPPING];
427
429
428
- unsigned char digest[this ->HASH_digest_length ];
430
+ unsigned char * digest = new unsigned char [this ->HASH_digest_length ];
429
431
430
432
// Computes the hash digest of the input 'HASH_number' times; each
431
433
// iteration combines the input char array with a different hash salt
@@ -435,7 +437,7 @@ int SBF::Check(char *string, int size)
435
437
buffer[j] = (char )(string[j]^this ->HASH_salt [k][j]);
436
438
}
437
439
438
- this ->Hash (buffer, size, (unsigned char *)& digest);
440
+ this ->Hash (buffer, size, (unsigned char *)digest);
439
441
440
442
// Truncates the digest to the first 32 bits
441
443
for (int i = 0 ; i < SBF::MAX_BYTE_MAPPING; i++){
@@ -460,6 +462,8 @@ int SBF::Check(char *string, int size)
460
462
else if (current_area < area) area = current_area;
461
463
}
462
464
465
+ delete[] buffer;
466
+ delete[] digest;
463
467
return area;
464
468
}
465
469
@@ -546,4 +550,4 @@ bool SBF::GetAreaFlotation(int area)
546
550
}
547
551
548
552
549
- } // namespace sbf
553
+ } // namespace sbf
0 commit comments