Eliminate static print buffer from prDbiOpenFlags()
authorPanu Matilainen <pmatilai@redhat.com>
Thu, 8 May 2008 14:10:10 +0000 (17:10 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Thu, 8 May 2008 14:10:10 +0000 (17:10 +0300)
- unlikely to actually overflow but it'd be all the more embarrasing
  as it's just diagnostics/debug code...

rpmdb/db3.c
rpmdb/dbconfig.c
rpmdb/rpmdb_internal.h

index fe2e0c5..e1983de 100644 (file)
@@ -238,9 +238,12 @@ static int db_init(dbiIndex dbi, const char * dbhome,
     eflags = (dbi->dbi_oeflags | dbi->dbi_eflags);
     if (eflags & DB_JOINENV) eflags &= DB_JOINENV;
 
-    if (dbfile)
+    if (dbfile) {
+       char *dbiflags = prDbiOpenFlags(eflags, 1);
        rpmlog(RPMLOG_DEBUG, "opening  db environment %s/%s %s\n",
-               dbhome, dbfile, prDbiOpenFlags(eflags, 1));
+               dbhome, dbfile, dbiflags);
+       free(dbiflags);
+    }
 
     /* XXX Can't do RPC w/o host. */
     if (dbi->dbi_host == NULL)
@@ -934,9 +937,12 @@ static int db3open(rpmdb rpmdb, rpmTag rpmtag, dbiIndex * dbip)
        }
     }
 
-    rpmlog(RPMLOG_DEBUG, "opening  db index       %s/%s %s mode=0x%x\n",
+    {  char *dbiflags = prDbiOpenFlags(oflags, 0);
+       rpmlog(RPMLOG_DEBUG, "opening  db index       %s/%s %s mode=0x%x\n",
                dbhome, (dbfile ? dbfile : rpmTagGetName(dbi->dbi_rpmtag)),
-               prDbiOpenFlags(oflags, 0), dbi->dbi_mode);
+               dbiflags, dbi->dbi_mode);
+       free(dbiflags);
+    }
 
     if (rc == 0) {
        static int _lockdbfd = 0;
index 02748ed..fc75af3 100644 (file)
@@ -10,6 +10,7 @@
 #include <rpm/rpmmacro.h>
 #include <rpm/rpmstring.h>
 #include <rpm/rpmlog.h>
+#include <rpm/argv.h>
 #include "rpmdb/rpmdb_internal.h"
 #include "debug.h"
 
@@ -434,14 +435,12 @@ dbiIndex db3New(rpmdb rpmdb, rpmTag rpmtag)
     return dbi;
 }
 
-const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
+char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
 {
-    static char buf[256];
+    ARGV_t flags = NULL;
     struct poptOption *opt;
-    char * oe;
+    char *buf;
 
-    oe = buf;
-    *oe = '\0';
     for (opt = rdbOptions; opt->longName != NULL; opt++) {
        if (opt->argInfo != POPT_BIT_SET)
            continue;
@@ -456,16 +455,18 @@ const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags)
        }
        if ((dbflags & opt->val) != opt->val)
            continue;
-       if (oe != buf)
-           *oe++ = ':';
-       oe = stpcpy(oe, opt->longName);
+       argvAdd(&flags, opt->longName);
        dbflags &= ~opt->val;
     }
     if (dbflags) {
-       if (oe != buf)
-           *oe++ = ':';
-           sprintf(oe, "0x%x", (unsigned)dbflags);
+       char *df = NULL;
+       rasprintf(&df, "0x%x", (unsigned)dbflags);
+       argvAdd(&flags, df);
+       free(df);
     }
+    buf = argvJoin(flags, ":");
+    argvFree(flags);
+       
     return buf;
 }
 
index 89bd4ee..40b3c13 100644 (file)
@@ -371,9 +371,9 @@ dbiIndex db3Free( dbiIndex dbi);
  * Format db3 open flags for debugging print.
  * @param dbflags              db open flags
  * @param print_dbenv_flags    format db env flags instead?
- * @return                     formatted flags (static buffer)
+ * @return                     formatted flags (malloced)
  */
-const char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
+char * prDbiOpenFlags(int dbflags, int print_dbenv_flags);
 
 /** \ingroup dbi
  * Return handle for an index database.