Introduction
Introduction Statistics Contact Development Disclaimer Help
pedantic snprintf() improvement - stagit-gopher - static git page generator for…
git clone git://git.codemadness.org/stagit-gopher
Log
Files
Refs
README
LICENSE
---
commit f8a73285fa1ba57d5815a9c365db13772896ad19
parent 77bfd42fb3c139ada3a679a62c56f6eebd38a0c2
Author: Hiltjo Posthuma <[email protected]>
Date: Sat, 9 Mar 2019 12:41:38 +0100
pedantic snprintf() improvement
POSIX says:
"If an output error was encountered, these functions shall return a negative
value and set errno to indicate the error."
Diffstat:
M stagit-gopher-index.c | 2 +-
M stagit-gopher.c | 6 +++---
2 files changed, 4 insertions(+), 4 deletions(-)
---
diff --git a/stagit-gopher-index.c b/stagit-gopher-index.c
@@ -117,7 +117,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const …
r = snprintf(buf, bufsiz, "%s%s%s",
path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", pat…
- if (r == -1 || (size_t)r >= bufsiz)
+ if (r < 0 || (size_t)r >= bufsiz)
errx(1, "path truncated: '%s%s%s'",
path, path[0] && path[strlen(path) - 1] != '/' ? "/" :…
}
diff --git a/stagit-gopher.c b/stagit-gopher.c
@@ -124,7 +124,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const …
r = snprintf(buf, bufsiz, "%s%s%s",
path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", pat…
- if (r == -1 || (size_t)r >= bufsiz)
+ if (r < 0 || (size_t)r >= bufsiz)
errx(1, "path truncated: '%s%s%s'",
path, path[0] && path[strlen(path) - 1] != '/' ? "/" :…
}
@@ -710,7 +710,7 @@ writelog(FILE *fp, const git_oid *oid)
git_oid_tostr(oidstr, sizeof(oidstr), &id);
r = snprintf(path, sizeof(path), "commit/%s.gph", oidstr);
- if (r == -1 || (size_t)r >= sizeof(path))
+ if (r < 0 || (size_t)r >= sizeof(path))
errx(1, "path truncated: 'commit/%s.gph'", oidstr);
r = access(path, F_OK);
@@ -935,7 +935,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
r = snprintf(filepath, sizeof(filepath), "file/%s.gph",
entrypath);
- if (r == -1 || (size_t)r >= sizeof(filepath))
+ if (r < 0 || (size_t)r >= sizeof(filepath))
errx(1, "path truncated: 'file/%s.gph'", entrypath);
if (!git_tree_entry_to_object(&obj, repo, entry)) {
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.