-
Notifications
You must be signed in to change notification settings - Fork 255
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
Draft
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.
Draft
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
d120e2d to
6975ad4
Compare
84658b7 to
90962f7
Compare
2aebeac to
56bf6aa
Compare
…attern Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
vsnprintf(3) returns an int. By using ssize_t, which is also signed, we avoid the need for a cast. Cc: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
There's nothing better that can be done. Cc: Serge Hallyn <serge@hallyn.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <douglas.mcilroy@dartmouth.edu> Signed-off-by: Alejandro Colomar <alx@kernel.org>
In the case of [v]snprintf_(), anticipate the rename in the next commit. Signed-off-by: Alejandro Colomar <alx@kernel.org>
For consistency with strTcpy(), call it sTprintf(). Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
Reported-by: Christopher Bazley <chris.bazley.wg14@gmail.com> Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
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 <alx@kernel.org>
56bf6aa to
e1a9b3b
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.
Queued after:
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
v14h
v14i
v15
interdiff
range-diff
v15b
v16
v16b
v17
v17b
v17c
v17d
v17e
v17f
v17g
v17h
v17i
v17j
v17k
v17l
v17m
v17n