INN commit: trunk (6 files)

INN Commit Russ_Allbery at isc.org
Thu Aug 9 13:18:07 UTC 2007


    Date: Thursday, August 9, 2007 @ 06:18:03
  Author: iulius
Revision: 7639

Use (v)asprintf instead of (v)snprintf.

Modified:
  trunk/frontends/feedone.c
  trunk/innd/cc.c
  trunk/innd/nc.c
  trunk/innfeed/imap_connection.c
  trunk/innfeed/innlistener.c
  trunk/lib/confparse.c

---------------------------+
 frontends/feedone.c       |    6 +-----
 innd/cc.c                 |    8 ++------
 innd/nc.c                 |    7 ++-----
 innfeed/imap_connection.c |    7 ++-----
 innfeed/innlistener.c     |    5 +----
 lib/confparse.c           |   16 ++--------------
 6 files changed, 10 insertions(+), 39 deletions(-)

Modified: frontends/feedone.c
===================================================================
--- frontends/feedone.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ frontends/feedone.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -78,7 +78,6 @@
     FILE	*F;
     char	buff[BUFSIZ];
     char	*mesgid = NULL;
-    size_t      length;
     char	*p;
     char	*q;
     bool	PostMode;
@@ -104,10 +103,7 @@
 	    PostMode = true;
 	    break;
 	case 'r':			/* Random Message-ID	*/
-            length = snprintf(NULL, 0, "<%ld@%ld>", (long) getpid(),
-                              (long) time(NULL));
-            mesgid = xmalloc(length + 1);
-            snprintf(mesgid, length, "<%ld@%ld>", (long) getpid(),
+            asprintf(&mesgid, "<%ld@%ld>", (long) getpid(),
                      (long) time(NULL));
 	    break;
 	case 't':

Modified: innd/cc.c
===================================================================
--- innd/cc.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ innd/cc.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -976,9 +976,8 @@
     char		*Name;
     char		*Rest;
     const char *		who;
-    char		*buff;
+    char		*buff = NULL;
     int			oerrno;
-    size_t              length;
 
     if (TIMES == NULL)
 	TIMES = concatpath(innconf->pathdb, INN_PATH_ACTIVETIMES);
@@ -1020,10 +1019,7 @@
 	who = av[2];
 	if (*who == '\0')
 	    who = NEWSMASTER;
-
-        length = snprintf(NULL, 0, "%s %ld %s\n", Name, (long) Now.tv_sec, who) + 1;
-        buff = xmalloc(length);
-        snprintf(buff, length, "%s %ld %s\n", Name, (long) Now.tv_sec, who);
+        asprintf(&buff, "%s %ld %s\n", Name, (long) Now.tv_sec, who);
 	if (xwrite(fd, buff, strlen(buff)) < 0) {
 	    oerrno = errno;
 	    syslog(L_ERROR, "%s cant write %s %m", LogName, TIMES);

Modified: innd/nc.c
===================================================================
--- innd/nc.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ innd/nc.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -315,8 +315,7 @@
     char	        *p;
     TOKEN		token;
     ARTHANDLE		*art;
-    char		*buff;
-    size_t              length;
+    char		*buff = NULL;
 
     /* Snip off the Message-ID. */
     for (p = cp->In.data + cp->Start + strlen("stat"); ISWHITE(*p); p++)
@@ -338,9 +337,7 @@
     SMfreearticle(art);
 
     /* Write the message. */
-    length = snprintf(NULL, 0, "%d 0 %s", NNTP_OK_STAT, p) + 1;
-    buff = xmalloc(length);
-    snprintf(buff, length, "%d 0 %s", NNTP_OK_STAT, p);
+    asprintf(&buff, "%d 0 %s", NNTP_OK_STAT, p);
     NCwritereply(cp, buff);
     free(buff);
 }

Modified: innfeed/imap_connection.c
===================================================================
--- innfeed/imap_connection.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ innfeed/imap_connection.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -2623,14 +2623,11 @@
 static conn_ret imap_sendKill(connection_t *cxn, unsigned uid)
 {
     conn_ret result;
-    char *tosend;
-    size_t length;
+    char *tosend = NULL;
 
     imap_GetTag(cxn);
 
-    length = 7 + 50 + 20;
-    tosend = xmalloc(length);
-    snprintf(tosend,length,"%s UID STORE %d +FLAGS.SILENT (\\Deleted)\r\n",
+    asprintf(&tosend, "%s UID STORE %d +FLAGS.SILENT (\\Deleted)\r\n",
              cxn->imap_currentTag, uid);
 
     result = WriteToWire_imapstr(cxn, tosend, -1);

Modified: innfeed/innlistener.c
===================================================================
--- innfeed/innlistener.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ innfeed/innlistener.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -711,14 +711,11 @@
 {
   pid_t myPid = getpid () ;
   const char *tapeDir = getTapeDirectory() ;
-  size_t len;
 
   if (dropArtFile != NULL)
     free (dropArtFile) ;
 
-  len = pathMax(tapeDir) + 1;
-  dropArtFile = xmalloc(len);
-  snprintf (dropArtFile,len,"%s/innfeed-dropped.%c%06d",
+  asprintf (&dropArtFile, "%s/innfeed-dropped.%c%06d",
             tapeDir, droppedFileCount + 'A', (int) myPid) ;
 
   if ((droppedFp = fopen (dropArtFile,"w")) == NULL)

Modified: lib/confparse.c
===================================================================
--- lib/confparse.c	2007-08-09 12:35:24 UTC (rev 7638)
+++ lib/confparse.c	2007-08-09 13:18:03 UTC (rev 7639)
@@ -1648,18 +1648,12 @@
                    const char *fmt, ...)
 {
     va_list args;
-    ssize_t length;
     char *message, *file;
     struct config_parameter *param;
 
     va_start(args, fmt);
-    length = vsnprintf(NULL, 0, fmt, args);
-    va_end(args);
-    if (length < 0)
+    if (vasprintf(&message, fmt, args) < 0)
         return;
-    message = xmalloc(length + 1);
-    va_start(args, fmt);
-    vsnprintf(message, length + 1, fmt, args);
     va_end(args);
 
     param = hash_lookup(group->params, key);
@@ -1683,17 +1677,11 @@
 config_error_group(struct config_group *group, const char *fmt, ...)
 {
     va_list args;
-    ssize_t length;
     char *message;
 
     va_start(args, fmt);
-    length = vsnprintf(NULL, 0, fmt, args);
-    va_end(args);
-    if (length < 0)
+    if (vasprintf(&message, fmt, args) < 0)
         return;
-    message = xmalloc(length + 1);
-    va_start(args, fmt);
-    vsnprintf(message, length + 1, fmt, args);
     va_end(args);
     warn("%s:%u: %s", group->file, group->line, message);
     free(message);



More information about the inn-committers mailing list