-
Notifications
You must be signed in to change notification settings - Fork 252
snprintf(3)-related improvements. #1148
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
Open
alejandro-colomar
wants to merge
12
commits into
shadow-maint:master
Choose a base branch
from
alejandro-colomar:snprintf_
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
snprintf(3)-related improvements. #1148
alejandro-colomar
wants to merge
12
commits into
shadow-maint:master
from
alejandro-colomar:snprintf_
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69952e7 to
6a65613
Compare
6a65613 to
99aef5b
Compare
1fad167 to
242ba52
Compare
242ba52 to
1c54632
Compare
edda7ae to
0d74116
Compare
c4c5268 to
4a540a9
Compare
e4469d9 to
a7e08cb
Compare
5f41652 to
48f98b5
Compare
9ebd267 to
6f02db4
Compare
6f02db4 to
11130d6
Compare
Closed
acbfe4f to
9ee62be
Compare
7096975 to
ef52e1c
Compare
92e3734 to
0e93a8b
Compare
29899e5 to
51e04ae
Compare
51e04ae to
17a1862
Compare
4c3583a to
7f8315d
Compare
…attern Signed-off-by: Alejandro Colomar <[email protected]>
…ncation Signed-off-by: Alejandro Colomar <[email protected]>
We can't pass more than an int to vnsprintf(3), so let's use the same type in our API. This allows us to remove a cast. Signed-off-by: Alejandro Colomar <[email protected]>
Make them report truncation via errno and NULL. Instead of having three possible returns (a pointer to the NUL byte, the end of the array, or NULL), reduce it to two possible ones: one for success, and one for error. Use errno, which is a common way to signal the specific error, and thus treat truncation as any other error. This simplifies error handling after these calls. Also, if one misuses a pointer after truncation, the results are better if the pointer is NULL: the program will easily abort. If we returned 'end', the program could more easily produce a buffer overrun. Suggested-by: Douglas McIlroy <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
For consistency with strTcpy(), call it sTprintf(). Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
This helps document the fact that these pointers are pointers to one-after-the-last element of an array. GCC currently has a bug by which it triggers a diagnostic in this code. However, it works just fine, and the diagnostic can be ignored. We're working on removing that false positive in GCC, so the diagnostic will eventually disappear. Link: <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108036> Signed-off-by: Alejandro Colomar <[email protected]>
These few lines are IMO more readable than the full-blown documentation. Signed-off-by: Alejandro Colomar <[email protected]>
The old name was too complex, and is inconsistent with all other sprintf(3)-based APIs having just one letter for differentiation. This allows breaking less lines. The original name was chosen for differentiation with the buggy Plan9 API seprint(2). However, 9front (the current fork where Plan9 is mainly developed) has acknowledged the bug. There's still no decision on fixing the bug or not, due to the age of their code base, and the projects depending on their library. It is under consideration inventing something like a seprint2(2) in 9front for replacement of seprint(2), but there's no decision yet either. Considering that 9front acknowledges their bug, and that they *may* release a fixed API with a similar name, we may as well claim that our seprintf() is also a fixed version of Plan9's seprint(2). It has a different name, after all (we terminate in 'f'). This commit was partially scripted with $ find * -type f \ | xargs grep -l stpeprintf \ | xargs sed -i 's/stpeprintf/seprintf/g'; Signed-off-by: Alejandro Colomar <[email protected]>
Reported-by: Christopher Bazley <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
Signed-off-by: Alejandro Colomar <[email protected]>
7f8315d to
2f03513
Compare
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Revisions:
v1b
v1c
v1d
v1e
v2
v3
v4
v5
v5b
v6
v7
v7b
v7c
v8
v8b
v8c
v8d
v8e
v9
const. [@chrisbazley]v9b
v9c
v9d
v9e
v9f
v9g
v9h
v9i
v9j
v9k
v9l
v9m
v10
#include "config.h"with quotes.v11
v11b
v12
v13
v13b
v13c
v13d
v13e
v14
v14b
v14c
v14d
v14e
v14f
v14g