quixdb / squash

Compression abstraction library and utilities
https://quixdb.github.io/squash/
MIT License
406 stars 53 forks source link

Feature : Act safely if no options are provided to var_args functions #188

Closed elliotwoods closed 8 years ago

elliotwoods commented 8 years ago

currently it can cause an access violation if you call function:

squash_codec_compress(this->squashCodec, &compressedSize, compressedData, uncompressedSize, uncompressedData);

rather than

squash_codec_compress(this->squashCodec, &compressedSize, compressedData, uncompressedSize, uncompressedData, NULL);

this is due to the empty arguments being interpreted as options, which are then processed and then we have a crash (in MSVC, i get an access violation on Debug but on Release it 'just works').

Dr-Emann commented 8 years ago

This is not possible in C. vararg functions do not know how many arguments they were passed, so there must be a sentinel value which designates the end of a list.

nemequ commented 8 years ago

Yep, @Dr-Emann is right.

On GCC we do use the sentinel attribute to indicate that a NULL is required, but I'm not aware of any equivalent for MSVC. If anyone is aware of something I'm willing to add it.

nemequ commented 8 years ago

FWIW, the sentinel attribute will work on clang and ICC, too. Basically everywhere except MSVC.