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

guillem pushed a commit to branch main
in repository dpkg.

View the commit online:
https://git.dpkg.org/cgit/dpkg/dpkg.git/commit/?id=78a970dba625039d654e51ae62a1cee310f0139a

commit 78a970dba625039d654e51ae62a1cee310f0139a
Author: Guillem Jover <[email protected]>
AuthorDate: Mon Jul 22 05:02:35 2024 +0200

    dpkg-deb: Track maintscript information in a new struct
    
    Instead of returning the interpreter name, and using a variable by
    reference for the script lines, pass a struct to track the script
    information. This simplifies the code and reduces the amount of
    allocated memory.
    
    Changelog: internal
---
 src/deb/info.c | 38 +++++++++++++++++++-------------------
 1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/src/deb/info.c b/src/deb/info.c
index 2ff5f1666..afe79011f 100644
--- a/src/deb/info.c
+++ b/src/deb/info.c
@@ -114,21 +114,25 @@ info_spew(const char *debar, const char *dir, const char 
*const *argv)
               "%d requested control components are missing", re), re);
 }
 
-static char *
-info_interpreter(FILE *cc, int *lines)
-{
+struct script {
   char interpreter[INTERPRETER_MAX + 1];
+  int lines;
+};
+
+static void
+info_script(FILE *cc, struct script *script)
+{
   int c;
 
-  *lines = 0;
-  interpreter[0] = '\0';
+  script->lines = 0;
+  script->interpreter[0] = '\0';
   if (getc(cc) == '#' && getc(cc) == '!') {
     char *p;
     int il;
 
     while ((c = getc(cc)) == ' ')
       ;
-    p = interpreter;
+    p = script->interpreter;
     *p++ = '#';
     *p++ = '!';
     il = 2;
@@ -139,14 +143,12 @@ info_interpreter(FILE *cc, int *lines)
     }
     *p = '\0';
     if (c == '\n')
-      (*lines)++;
+      script->lines++;
   }
   while ((c = getc(cc)) != EOF) {
     if (c == '\n')
-      (*lines)++;
+      script->lines++;
   }
-
-  return m_strdup(interpreter);
 }
 
 static void
@@ -174,27 +176,25 @@ info_list(const char *debar, const char *dir)
       ohshite(_("cannot get file '%.255s' metadata"), controlfile.buf);
     if (S_ISREG(stab.st_mode)) {
       int exec_mark = (S_IXUSR & stab.st_mode) ? '*' : ' ';
-      char *interpreter;
-      int lines;
+      struct script script;
 
       cc = fopen(controlfile.buf, "r");
       if (!cc)
         ohshite(_("cannot open file '%.255s'"), controlfile.buf);
 
-      interpreter = info_interpreter(cc, &lines);
+      info_script(cc, &script);
 
       if (ferror(cc))
         ohshite(_("cannot read file '%.255s'"), controlfile.buf);
       fclose(cc);
-      if (str_is_set(interpreter))
+
+      if (str_is_set(script.interpreter))
         printf(_(" %7jd bytes, %5d lines   %c  %-20.127s %.127s\n"),
-               (intmax_t)stab.st_size, lines, exec_mark, cdep->d_name,
-               interpreter);
+               (intmax_t)stab.st_size, script.lines, exec_mark, cdep->d_name,
+               script.interpreter);
       else
         printf(_(" %7jd bytes, %5d lines   %c  %.127s\n"),
-               (intmax_t)stab.st_size, lines, exec_mark, cdep->d_name);
-
-      free(interpreter);
+               (intmax_t)stab.st_size, script.lines, exec_mark, cdep->d_name);
     } else {
       printf(_("     not a plain file          %.255s\n"), cdep->d_name);
     }

-- 
Dpkg.Org's dpkg

Reply via email to