con33-c new NCCE/CS - #75
Conversation
sei-jsible
left a comment
There was a problem hiding this comment.
I also feel like this example has gotten too convoluted and unclear what it's supposed to be doing. Perhaps instead, the example should just be two different threads tokenizing two unrelated strings.
| if (mtx_unlock(&lock) == thrd_error) { | ||
| return -1; /* Indicate error to caller */ | ||
| } | ||
| return t[0]; |
There was a problem hiding this comment.
This seems like a bad example, since if str could vary instead of being hardcoded, then this could potentially be a NULL dereference.
There was a problem hiding this comment.
I've changed str from a string literal to argv[1] and made sure it exists. So it cannot be NULL.
There was a problem hiding this comment.
t can be NULL even if str isn't, because the string might have run out of tokens already.
There was a problem hiding this comment.
I added null checks before each t[0].
There was a problem hiding this comment.
Are you sure they pushed successfully? I don't see them still.
| </p></td><td><p>A sequence of calls of the strtok function is made from different threads (7.26.5.9). | ||
| </p></td><td><p><a href="/sei-cert-c-coding-standard/rules/concurrency-con/con33-c">CON33-C</a></p></td></tr> | ||
| </p></td></tr><tr class="even"><td><div class="content-wrapper"><p>200 <a id="CC.UndefinedBehavior-ub_200"></a></p></div></td><td><p><img src="images/icons/emoticons/warning.svg" /></p></td><td><p>The first argument in the very first call to the <code> strtok </code> or <code> wcstok </code> is a null pointer (7.26.5.9, 7.31.4.5.8).</p></td><td><p><br /> |
There was a problem hiding this comment.
| </p></td><td><p>A sequence of calls of the strtok function is made from different threads (7.26.5.9). | |
| </p></td><td><p><a href="/sei-cert-c-coding-standard/rules/concurrency-con/con33-c">CON33-C</a></p></td></tr> | |
| </p></td></tr><tr class="even"><td><div class="content-wrapper"><p>200 <a id="CC.UndefinedBehavior-ub_200"></a></p></div></td><td><p><img src="images/icons/emoticons/warning.svg" /></p></td><td><p>The first argument in the very first call to the <code> strtok </code> or <code> wcstok </code> is a null pointer (7.26.5.9, 7.31.4.5.8).</p></td><td><p><br /> | |
| </p></td><td><p>A sequence of calls of the strtok function is made from different threads (7.26.5.9).</p></td><td><p><a href="/sei-cert-c-coding-standard/rules/concurrency-con/con33-c">CON33-C</a></p></td></tr><tr class="even"><td><div class="content-wrapper"><p>200 <a id="CC.UndefinedBehavior-ub_200"></a></p></div></td><td><p><img src="images/icons/emoticons/warning.svg" /></p></td><td><p>The first argument in the very first call to the <code> strtok </code> or <code> wcstok </code> is a null pointer (7.26.5.9, 7.31.4.5.8).</p></td><td><p><br /> |
There was a problem hiding this comment.
It looks like you did something similar to this, but there's still two </p></td></tr>s immediately in a row (end of 170 and beginning of 171).
…on/05.con33-c.md Co-authored-by: sei-jsible <105077289+sei-jsible@users.noreply.github.com>
No description provided.