stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
bb1d06eb204b1d1135fcddccd14f6306abcd7f72
parent
587b01428d6ec2be1ab6b468198663118d483990
Author
Hiltjo Posthuma <hiltjo@codemadness.org>
Date
2019-03-09 11:39
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-index.c 2 +-
M stagit.c 6 +++---

2 files changed, 4 insertions, 4 deletions


diff --git a/stagit-index.c b/stagit-index.c

@@ -28,7 +28,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
   28    28 
   29    29 	r = snprintf(buf, bufsiz, "%s%s%s",
   30    30 		path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
   31    -1 	if (r == -1 || (size_t)r >= bufsiz)
   -1    31 	if (r < 0 || (size_t)r >= bufsiz)
   32    32 		errx(1, "path truncated: '%s%s%s'",
   33    33 			path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
   34    34 }

diff --git a/stagit.c b/stagit.c

@@ -76,7 +76,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
   76    76 
   77    77 	r = snprintf(buf, bufsiz, "%s%s%s",
   78    78 		path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
   79    -1 	if (r == -1 || (size_t)r >= bufsiz)
   -1    79 	if (r < 0 || (size_t)r >= bufsiz)
   80    80 		errx(1, "path truncated: '%s%s%s'",
   81    81 			path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
   82    82 }
@@ -616,7 +616,7 @@ writelog(FILE *fp, const git_oid *oid)
  616   616 
  617   617 		git_oid_tostr(oidstr, sizeof(oidstr), &id);
  618   618 		r = snprintf(path, sizeof(path), "commit/%s.html", oidstr);
  619    -1 		if (r == -1 || (size_t)r >= sizeof(path))
   -1   619 		if (r < 0 || (size_t)r >= sizeof(path))
  620   620 			errx(1, "path truncated: 'commit/%s.html'", oidstr);
  621   621 		r = access(path, F_OK);
  622   622 
@@ -856,7 +856,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
  856   856 
  857   857 		r = snprintf(filepath, sizeof(filepath), "file/%s.html",
  858   858 		         entrypath);
  859    -1 		if (r == -1 || (size_t)r >= sizeof(filepath))
   -1   859 		if (r < 0 || (size_t)r >= sizeof(filepath))
  860   860 			errx(1, "path truncated: 'file/%s.html'", entrypath);
  861   861 
  862   862 		if (!git_tree_entry_to_object(&obj, repo, entry)) {