What happens if I forget to close a scanset? : <p>Suppose I forgot to close the right square bracket <code>]</code> of a scanset. What will happen then? Does it invoke Undefined Behavior?</p>

<p>Example:</p>

<pre><code>char str[] = "Hello! One Two Three";
char s1[50] = {0}, s2[50] = {0};
sscanf(str, "%s %[^h", s1, s2); /* UB? */
printf("s1='%s' s2='%s'\n", s1, s2);
</code></pre>

<p>I get a warning from GCC when compiling:</p>

<pre><code>source_file.c: In function ‘main’:
source_file.c:11:5: warning: no closing ‘]’ for ‘%[’ format [-Wformat=]
     sscanf(str, "%s %[^h", s1, s2); /* UB? */
</code></pre>

<p>and the output as</p>

<pre><code>s1='Hello!' s2=''
</code></pre>

<p>I've also noticed that the <code>sscanf</code> returns 1. But what exactly is going on here?</p>

<p>I've checked the C11 standard, but found no information related to this.</p>
