Nice. Comprehensive unit tests are indeed welcome.
Even a simple test code that tests all features, flags combinations, etc, and outputs a log.
It will make easy for anyone to run it and compare the logs.
I had a bug:
u_printf( my_output_cb, NULL, "%d" NL, -42 );
prints:
--42
I may have found an explanation.
In u_parse_format(),
case 'i':
calls
u_itoa( value, buffer, 10, false );
which outputs minus sign.
Then
if ( number )
does
if ( sign )
{
output_cb( '-', ctx );
chars_written++;
}
which outputs another minus sign.
Nice work. I always have understood that snprintf does not write a null character when the produced string is longer than the given size. The snprintf function also can be called with a null pointer to calculate the length of the produced string.
> I always have understood that snprintf does not write a null character when the produced string is longer than the given size.
snprintf always null-terminates when the buffer length is greater than 0 and there's no error. That is, if snprintf returns >= 0 and the buffer length is > 0, the output is null-terminated.
Thanks, I will make and add unit tests As you requested, I'm already starting to do it, but in the meantime, if you want, you can support the project with a star. :)
Would be nice to know the code size e.g. on arm-none-eabi!
Nice. Comprehensive unit tests are indeed welcome. Even a simple test code that tests all features, flags combinations, etc, and outputs a log. It will make easy for anyone to run it and compare the logs.
I had a bug:
prints:--42
I may have found an explanation. In u_parse_format(), case 'i': calls u_itoa( value, buffer, 10, false ); which outputs minus sign.
Then if ( number ) does if ( sign ) { output_cb( '-', ctx ); chars_written++; } which outputs another minus sign.
Also floats seem to "forget" the integer part, and also have two minus signs when negative.
Created
https://github.com/Ferki-git-creator/Uprintf/issues/1
https://github.com/Ferki-git-creator/Uprintf/issues/2
https://github.com/Ferki-git-creator/Uprintf/pull/3
https://github.com/Ferki-git-creator/Uprintf/pull/4
Nice work. I always have understood that snprintf does not write a null character when the produced string is longer than the given size. The snprintf function also can be called with a null pointer to calculate the length of the produced string.
You could add a c file with some unittests.
> I always have understood that snprintf does not write a null character when the produced string is longer than the given size.
snprintf always null-terminates when the buffer length is greater than 0 and there's no error. That is, if snprintf returns >= 0 and the buffer length is > 0, the output is null-terminated.
This should be clear from your local snprintf(3) man page (e.g. https://man.openbsd.org/snprintf), but also see the C23 standard (https://www.open-std.org/jtc1/sc22/wg14/www/docs/n3220.pdf) and POSIX (https://pubs.opengroup.org/onlinepubs/9799919799/).
Thanks, I will make and add unit tests As you requested, I'm already starting to do it, but in the meantime, if you want, you can support the project with a star. :)