[Rpm-maint] [PATCH] Fix segfault and other annoyances in %{lua:...}

Peter Jones pjones at redhat.com
Thu Nov 1 23:05:40 UTC 2007


This patch fixes a segfault, and also makes it possible to emit output 
from lua macros without forcing a trailing newline.  If it's ok with 
everbody, I can just commit it to hg.

pjones2:~/devel/rpm$ hg diff
diff -r 86686df777f4 rpmio/rpmlua.c
--- a/rpmio/rpmlua.c    Wed Oct 31 12:48:43 2007 +0200
+++ b/rpmio/rpmlua.c    Thu Nov 01 19:02:32 2007 -0400
@@ -130,6 +130,7 @@ void rpmluaSetPrintBuffer(rpmlua _lua, i
      free(lua->printbuf);
      lua->printbuf = NULL;
      lua->printbufsize = 0;
+    lua->printbufused = 0;
  }

  const char *rpmluaGetPrintBuffer(rpmlua _lua)
@@ -745,15 +746,13 @@ static int rpm_print (lua_State *L)
         }
         lua_pop(L, 1);  /* pop result */
      }
-    lua_pop(L, 1);
      if (!lua->storeprint) {
         (void) fputs("\n", stdout);
      } else {
-       if (lua->printbufused+1 >= lua->printbufsize) {
+       if (lua->printbufused+1 > lua->printbufsize) {
             lua->printbufsize += 512;
             lua->printbuf = xrealloc(lua->printbuf, lua->printbufsize);
         }
-       lua->printbuf[lua->printbufused++] = '\n';
         lua->printbuf[lua->printbufused] = '\0';
      }
      return 0;

-- 
   Peter



More information about the Rpm-maint mailing list