This is an automated email from the git hooks/post-receive script.

guillem pushed a commit to branch master
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=05c5c373dad18117942ea59440f9867c2f0d6a73

commit 05c5c373dad18117942ea59440f9867c2f0d6a73
Author: Guillem Jover <guil...@debian.org>
AuthorDate: Thu Jul 12 03:22:37 2018 +0200

    Switch from strchr() + strlen() to strchrnul()
---
 debian/changelog          | 1 +
 dselect/baselist.cc       | 7 ++++---
 dselect/pkginfo.cc        | 6 +++---
 lib/dpkg/pkg-format.c     | 7 ++-----
 src/help.c                | 6 +++---
 src/main.c                | 7 ++++---
 utils/start-stop-daemon.c | 8 ++++----
 7 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index 264730e2f..5dfc4ae03 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -192,6 +192,7 @@ dpkg (1.19.1) UNRELEASED; urgency=medium
       This should reduce the run-time memory used.
     - libdpkg: Reset nfiles in files_db_reset().
     - libdpkg: Split push_cleanup() into push_cleanup_fallback().
+    - Switch from strchr() + strlen() to strchrnul().
   * Build system:
     - Set distribution tarball format to ustar, instead of default v7 format.
     - Mark PO4A and POD2MAN as precious variables.
diff --git a/dselect/baselist.cc b/dselect/baselist.cc
index 05465fc92..6fd769239 100644
--- a/dselect/baselist.cc
+++ b/dselect/baselist.cc
@@ -410,8 +410,8 @@ void baselist::wordwrapinfo(int offset, const char *m) {
 
   for (;;) {
     int offleft=offset; while (*m == ' ' && offleft>0) { m++; offleft--; }
-    const char *p= strchr(m,'\n');
-    int l= p ? (int)(p-m) : strlen(m);
+    const char *p = strchrnul(m, '\n');
+    int l = (int)(p - m);
     while (l && c_isspace(m[l - 1]))
       l--;
     if (!l || (*m == '.' && l == 1)) {
@@ -452,7 +452,8 @@ void baselist::wordwrapinfo(int offset, const char *m) {
       }
       wrapping = true;
     }
-    if (!p) break;
+    if (*p == '\0')
+      break;
     if (getcury(infopad) == (MAX_DISPLAY_INFO - 1)) {
       waddstr(infopad,
               "[The package description is too long and has been 
truncated...]");
diff --git a/dselect/pkginfo.cc b/dselect/pkginfo.cc
index e11067fdf..31a45994f 100644
--- a/dselect/pkginfo.cc
+++ b/dselect/pkginfo.cc
@@ -114,14 +114,14 @@ void packagelist::itd_description() {
       m = table[cursorline]->pkg->installed.description;
     if (str_is_unset(m))
       m = _("No description available.");
-    const char *p= strchr(m,'\n');
-    int l= p ? (int)(p-m) : strlen(m);
+    const char *p = strchrnul(m, '\n');
+    int l = (int)(p - m);
     wattrset(infopad, part_attr[info_head]);
     waddstr(infopad, table[cursorline]->pkg->set->name);
     waddstr(infopad," - ");
     waddnstr(infopad,m,l);
     wattrset(infopad, part_attr[info_body]);
-    if (p) {
+    if (*p) {
       waddstr(infopad,"\n\n");
       wordwrapinfo(1,++p);
     }
diff --git a/lib/dpkg/pkg-format.c b/lib/dpkg/pkg-format.c
index 50c8bc581..aa2372a64 100644
--- a/lib/dpkg/pkg-format.c
+++ b/lib/dpkg/pkg-format.c
@@ -194,11 +194,8 @@ pkg_format_parse(const char *fmt, struct dpkg_error *err)
                        fmtend = fmt;
                        do {
                                fmtend += 1;
-                               fmtend = strchr(fmtend, '$');
-                       } while (fmtend && fmtend[1] != '{');
-
-                       if (!fmtend)
-                               fmtend = fmt + strlen(fmt);
+                               fmtend = strchrnul(fmtend, '$');
+                       } while (fmtend[0] && fmtend[1] != '{');
 
                        if (!parsestring(node, fmt, fmtend - 1, err)) {
                                pkg_format_free(head);
diff --git a/src/help.c b/src/help.c
index cfcdd8ebf..e4db356bd 100644
--- a/src/help.c
+++ b/src/help.c
@@ -90,9 +90,9 @@ find_command(const char *prog)
   if (!path_list)
     ohshit(_("PATH is not set"));
 
-  for (path = path_list; path; path = path_end ? path_end + 1 : NULL) {
-    path_end = strchr(path, ':');
-    path_len = path_end ? (size_t)(path_end - path) : strlen(path);
+  for (path = path_list; path; path = *path_end ? path_end + 1 : NULL) {
+    path_end = strchrnul(path, ':');
+    path_len = (size_t)(path_end - path);
 
     varbuf_reset(&filename);
     varbuf_add_buf(&filename, path, path_len);
diff --git a/src/main.c b/src/main.c
index 0a45f812e..c1276c96d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -642,8 +642,8 @@ set_force(const struct cmdinfo *cip, const char *value)
   }
 
   for (;;) {
-    comma= strchr(value,',');
-    l = comma ? (size_t)(comma - value) : strlen(value);
+    comma = strchrnul(value, ',');
+    l = (size_t)(comma - value);
     for (fip=forceinfos; fip->name; fip++)
       if (strncmp(fip->name, value, l) == 0 && strlen(fip->name) == l)
         break;
@@ -661,7 +661,8 @@ set_force(const struct cmdinfo *cip, const char *value)
       warning(_("obsolete force/refuse option '%s'"), fip->name);
     }
 
-    if (!comma) break;
+    if (*comma == '\0')
+      break;
     value= ++comma;
   }
 }
diff --git a/utils/start-stop-daemon.c b/utils/start-stop-daemon.c
index e9720425a..e0339c4cc 100644
--- a/utils/start-stop-daemon.c
+++ b/utils/start-stop-daemon.c
@@ -930,15 +930,15 @@ parse_schedule(const char *schedule_str)
        } else {
                count = 0;
                repeatat = -1;
-               while (schedule_str != NULL) {
-                       slash = strchr(schedule_str, '/');
-                       str_len = slash ? (size_t)(slash - schedule_str) : 
strlen(schedule_str);
+               while (*schedule_str) {
+                       slash = strchrnul(schedule_str, '/');
+                       str_len = (size_t)(slash - schedule_str);
                        if (str_len >= sizeof(item_buf))
                                badusage("invalid schedule item: far too long"
                                         " (you must delimit items with 
slashes)");
                        memcpy(item_buf, schedule_str, str_len);
                        item_buf[str_len] = '\0';
-                       schedule_str = slash ? slash + 1 : NULL;
+                       schedule_str = *slash ? slash + 1 : slash;
 
                        parse_schedule_item(item_buf, &schedule[count]);
                        if (schedule[count].type == sched_forever) {

-- 
Dpkg.Org's dpkg

Reply via email to