@@ -370,13 +370,13 @@ void SBF::SaveToDisk(std::string path, int mode)
370370// int area the area label
371371void SBF::Insert (char *string, int size, int area)
372372{
373- char buffer[size];
373+ char * buffer = new char [size];
374374
375375 // We allow a maximum SBF mapping of 32 bit (resulting in 2^32 cells).
376376 // Thus, the hash digest is limited to the first four bytes.
377377 unsigned char digest32[SBF::MAX_BYTE_MAPPING];
378378
379- unsigned char digest[this ->HASH_digest_length ];
379+ unsigned char * digest = new unsigned char [this ->HASH_digest_length ];
380380
381381 // Computes the hash digest of the input 'HASH_number' times; each
382382 // iteration combines the input char array with a different hash salt
@@ -386,7 +386,7 @@ void SBF::Insert(char *string, int size, int area)
386386 buffer[j] = (char )(string[j]^this ->HASH_salt [k][j]);
387387 }
388388
389- this ->Hash (buffer, size, (unsigned char *)& digest);
389+ this ->Hash (buffer, size, (unsigned char *)digest);
390390
391391 // Truncates the digest after the first 32 bits (see above)
392392 for (int i = 0 ; i < SBF::MAX_BYTE_MAPPING; i++){
@@ -408,6 +408,8 @@ void SBF::Insert(char *string, int size, int area)
408408 this ->members ++;
409409 this ->AREA_members [area]++;
410410
411+ delete[] buffer;
412+ delete[] digest;
411413}
412414
413415// 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)
417419// int size length of the element
418420int SBF::Check (char *string, int size)
419421{
420- char buffer[size];
422+ char * buffer = new char [size];
421423 int area = 0 ;
422424 int current_area = 0 ;
423425
424426 // We allow a maximum SBF mapping of 32 bit (resulting in 2^32 cells).
425427 // Thus, the hash digest is limited to the first four bytes.
426428 unsigned char digest32[SBF::MAX_BYTE_MAPPING];
427429
428- unsigned char digest[this ->HASH_digest_length ];
430+ unsigned char * digest = new unsigned char [this ->HASH_digest_length ];
429431
430432 // Computes the hash digest of the input 'HASH_number' times; each
431433 // iteration combines the input char array with a different hash salt
@@ -435,7 +437,7 @@ int SBF::Check(char *string, int size)
435437 buffer[j] = (char )(string[j]^this ->HASH_salt [k][j]);
436438 }
437439
438- this ->Hash (buffer, size, (unsigned char *)& digest);
440+ this ->Hash (buffer, size, (unsigned char *)digest);
439441
440442 // Truncates the digest to the first 32 bits
441443 for (int i = 0 ; i < SBF::MAX_BYTE_MAPPING; i++){
@@ -460,6 +462,8 @@ int SBF::Check(char *string, int size)
460462 else if (current_area < area) area = current_area;
461463 }
462464
465+ delete[] buffer;
466+ delete[] digest;
463467 return area;
464468}
465469
@@ -546,4 +550,4 @@ bool SBF::GetAreaFlotation(int area)
546550}
547551
548552
549- } // namespace sbf
553+ } // namespace sbf
0 commit comments