Skip to content

con33-c new NCCE/CS - #75

Open
sei-dsvoboda wants to merge 13 commits into
mainfrom
con33-strtok
Open

con33-c new NCCE/CS#75
sei-dsvoboda wants to merge 13 commits into
mainfrom
con33-strtok

Conversation

@sei-dsvoboda

Copy link
Copy Markdown
Contributor

No description provided.

@sei-dsvoboda
sei-dsvoboda requested review from a team and sei-jsible July 6, 2026 21:13
Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated
Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated

@sei-jsible sei-jsible left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems like a bad example, since if str could vary instead of being hardcoded, then this could potentially be a NULL dereference.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed str from a string literal to argv[1] and made sure it exists. So it cannot be NULL.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

t can be NULL even if str isn't, because the string might have run out of tokens already.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added null checks before each t[0].

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure they pushed successfully? I don't see them still.

Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated
Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated
Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated
Comment thread content/4.sei-cert-c-coding-standard/03.rules/05.concurrency-con/05.con33-c.md Outdated
Comment on lines 165 to 167
</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 />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
</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 />

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants