Björkus "No time_t to Die" Dorkus<p>Time to get printf to the SIZE_MAX off the ground. Especially since it's not the type that matters for the precision specifier for the string size, it's the actual value.</p><pre><code>#include <stdio.h><br>#include <stdlib.h><br>#include <limits.h><br>#include <assert.h><br><br>int main() {<br> enum { COUNT = 10, BYTESIZE = INT_MAX / COUNT };<br> char* str = (char*)malloc(BYTESIZE + 1);<br> for (size_t i = 0; i < BYTESIZE; ++i) {<br> str[i] = 'a';<br> }<br> str[BYTESIZE] = '\0';<br> FILE* f = fopen("/dev/null", "w+");<br> [[maybe_unused]] int write_value = fprintf(f, "%.*s", BYTESIZE, str);<br> [[maybe_unused]] int large_write_value = fprintf(f, "%.*s %*.s %*.s %*.s %*.s %*.s %*.s %*.s %*.s %*.s %*.s",<br> BYTESIZE, str, BYTESIZE, str, BYTESIZE, str, BYTESIZE, str, BYTESIZE, str, BYTESIZE, str, BYTESIZE, str,<br> BYTESIZE, str, BYTESIZE, str, BYTESIZE, str, BYTESIZE, str);<br> free(str);<br> assert(write_value == BYTESIZE); // Well.<br> assert(large_write_value == -1); // ... Okay.<br> // this should let the other thing work out nicely, then.<br> return 0;<br>}<br></code></pre>