Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some tests of the snprintf results appear to be off by one in the papi code #40

Open
wcohen opened this issue Jun 29, 2023 · 0 comments
Labels
type-bug Issues discussing bugs or PRs fixing bugs

Comments

@wcohen
Copy link
Contributor

wcohen commented Jun 29, 2023

I was working on addressing some of the issues found by coverity in papi (https://github.com/wcohen/papi/tree/coverity202307). In particular there were some possibly non-null terminated strings due to the string being larger than the buffer (wcohen@83ae483). When developing that particular fix I looked to see how other places in the papi had addressed that issue. Other places in were using snprintf and checking the value returned by the function. I noticed that some source code such as src/components/pcp/linux-pcp.c would flag errors when the return value was larger than the size passed in, but other such as src/components/sysdetect/nvidia_gpu.c and src/components/sysdetect/amd_gpu.c would flag an error if the size return was EQUAL to or larger than the size passed in. Both of the following links mention that the NULL at the end of the string is not counted in that total count returned by snprintf:

https://www.geeksforgeeks.org/snprintf-c-library/
https://cplusplus.com/reference/cstdio/snprintf/

That would mean that a number of the tests checking the return value of snprintf are off by one. The tests should be flagging an error if snprintf returns a value equal to or greater than the buffer size rather than only greater than the buffer size.

@gcongiu gcongiu added the type-bug Issues discussing bugs or PRs fixing bugs label Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Issues discussing bugs or PRs fixing bugs
Projects
None yet
Development

No branches or pull requests

2 participants