alelievr / libft-unit-test

455 stars 88 forks source link

ctype tests with undefined behavior #92

Closed fletcher97 closed 1 year ago

fletcher97 commented 3 years ago

According to C standard section 7.4 paragraph 1:

In all cases the argument is an int, the value of which shall be representable as an unsigned char or shall equal the value of the macro EOF . If the argument has any other value, the behavior is undefined.

In your tests you are testing values ranging from -1 to 530 in the is... functions and -100 to 530 in the to... functions. Not sure how this handles in OS X but I'm using linux and it's giving me "FAILED" in some functions like isalnum. The function is literally return (ft_isalpha(c) || ft_isdigit(c)); and they both isalpha and isdigit passed. The undefined behavior is considering 262 as an alnum according to the c implementation when the input itself is wrong.

The test should only go up to 255 and include EOF to avoid comparing undefined behavior as it gives no meaningful information and may fails the program when there is nothing wrong with it.

Exemple (the 262 was the value that failed isalnum and r:1 is the return of the standard isalnum converted to 0 or 1 so it's returning true):

image

github-actions[bot] commented 2 years ago

Hello! Thanks for contributing to the libft unit test.

Note that this repository is not maintained by the owner anymore, instead there is a bot that will automatically merge any reviewed pull requests. If you feel like it, here are some links that can help you submiting a change in the code base::