logo

etc_portage

Unnamed repository; edit this file 'description' to name the repository. git clone https://hacktivis.me/git/etc_portage.git

0006-pedantic-snprintf-improvement.patch (2166B)


  1. From bb1d06eb204b1d1135fcddccd14f6306abcd7f72 Mon Sep 17 00:00:00 2001
  2. From: Hiltjo Posthuma <hiltjo@codemadness.org>
  3. Date: Sat, 9 Mar 2019 12:39:10 +0100
  4. Subject: [PATCH 06/22] pedantic snprintf() improvement
  5. POSIX says:
  6. "If an output error was encountered, these functions shall return a negative
  7. value and set errno to indicate the error."
  8. ---
  9. stagit-index.c | 2 +-
  10. stagit.c | 6 +++---
  11. 2 files changed, 4 insertions(+), 4 deletions(-)
  12. diff --git a/stagit-index.c b/stagit-index.c
  13. index accb1a5..cc70e4d 100644
  14. --- a/stagit-index.c
  15. +++ b/stagit-index.c
  16. @@ -28,7 +28,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
  17. r = snprintf(buf, bufsiz, "%s%s%s",
  18. path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
  19. - if (r == -1 || (size_t)r >= bufsiz)
  20. + if (r < 0 || (size_t)r >= bufsiz)
  21. errx(1, "path truncated: '%s%s%s'",
  22. path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
  23. }
  24. diff --git a/stagit.c b/stagit.c
  25. index b8abea3..1fc6c1e 100644
  26. --- a/stagit.c
  27. +++ b/stagit.c
  28. @@ -76,7 +76,7 @@ joinpath(char *buf, size_t bufsiz, const char *path, const char *path2)
  29. r = snprintf(buf, bufsiz, "%s%s%s",
  30. path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
  31. - if (r == -1 || (size_t)r >= bufsiz)
  32. + if (r < 0 || (size_t)r >= bufsiz)
  33. errx(1, "path truncated: '%s%s%s'",
  34. path, path[0] && path[strlen(path) - 1] != '/' ? "/" : "", path2);
  35. }
  36. @@ -616,7 +616,7 @@ writelog(FILE *fp, const git_oid *oid)
  37. git_oid_tostr(oidstr, sizeof(oidstr), &id);
  38. r = snprintf(path, sizeof(path), "commit/%s.html", oidstr);
  39. - if (r == -1 || (size_t)r >= sizeof(path))
  40. + if (r < 0 || (size_t)r >= sizeof(path))
  41. errx(1, "path truncated: 'commit/%s.html'", oidstr);
  42. r = access(path, F_OK);
  43. @@ -856,7 +856,7 @@ writefilestree(FILE *fp, git_tree *tree, const char *path)
  44. r = snprintf(filepath, sizeof(filepath), "file/%s.html",
  45. entrypath);
  46. - if (r == -1 || (size_t)r >= sizeof(filepath))
  47. + if (r < 0 || (size_t)r >= sizeof(filepath))
  48. errx(1, "path truncated: 'file/%s.html'", entrypath);
  49. if (!git_tree_entry_to_object(&obj, repo, entry)) {
  50. --
  51. 2.26.2