cpython icon indicating copy to clipboard operation
cpython copied to clipboard

Add a warning message about PyOS_snprintf

Open eric-wieser opened this issue 1 year ago • 0 comments

The top google result for "determine sprintf buffer size" is https://stackoverflow.com/a/3923207/102441, which advocates code along the lines of

int size = snprintf(NULL, 0, "%d", 132);
char * a = malloc(size + 1);
sprintf(a, "%d", 132);

Unfortunately, this does not work for PyOS_snprintf, as it includes an assert to ensure the arguments are not NULL and 0.

This PR simply documents this limitation.

eric-wieser avatar Aug 15 '22 10:08 eric-wieser