[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [leafnode-list] leafnode does not display groups



Joerg Dietrich wrote:

> On Fri, Apr 21, 2000 at 10:03:51AM +0200, david van zeebroeck wrote:
> > ran fetchnews -vvv -f
> > no problem there it created a groupfile with entries like this :
> > 3dfx.d3d 1u 1u 0u -x-
>             ^  ^  ^
> Arghh! Cornelius' snprintf only understands %ul and not %lu.

This is obviously a bug. The following patch (against 1.9.13) should
cure the problem more thoroughly than Joerg's patch. I hope that I
did comprehend the man page this time. I haven't run extensive tests on
it, but it seems to be able to reproduce a line from the active file
quite nicely.

--Cornelius (forced back from the Pennines by a severe cold).

%snip

--- leafnode-1.9.13/miscutil.c	Sun Apr  9 14:05:11 2000
+++ leafnode-1.9.14/miscutil.c	Mon Apr 24 16:58:21 2000
@@ -528,7 +528,7 @@
 /*
  * poor man's snprintf() - for systems which don't have their own
  *
- * This version of snprintf() currently supports only %s, %c, %d, %ud, %ul, %l.
+ * This version of snprintf() currently supports only %s, %c, %d, %u, %ld, %lu.
  * It also behaves differently from standard snprintf() in that if the
  * output is truncated, it will return -1. Otherwise, it will return the
  * number of printed chars.
@@ -560,7 +560,7 @@
     const char *p;
     char *q;
     int flag  = 0;
-    int uflag = 0;
+    int lflag = 0;	/* checking for longs */
     int i     = 1;	/* because the terminating \0 also counts */
     size_t len;
     char   buf[30];	/* buffer for converting longs and ints */
@@ -575,7 +575,7 @@
     q = str;
     while ( p && *p && ( i < n ) ) {
     	if ( ( *p == '%' )  && !flag ) {
-	    uflag = 0;
+	    lflag = 0;
 	    flag  = 1;
 	    *p++;
 	}
@@ -595,51 +595,56 @@
 		    break;
 		}
 		case 'u': {
-		    /* next argument will be unsigned ! */
-		    uflag = 1;
+		    if ( lflag ) {
+			l = va_arg( ap, unsigned long );
+			sprintf( buf, "%lu", l );
+		    }
+		    else {
+			d = va_arg( ap, unsigned int );
+			sprintf( buf, "%u", d );
+		    }
+                    len = strlen( buf );
+                    if ( len > (n-i) )
+                        len = n-i;
+                    *q = '\0';
+                    strncat( q, buf, len );
+                    q += len;
+                    i += len;
+		    lflag = 0;
+		    flag  = 0;
 		    p++;
 		    break;
 		}
-		case 'd':
-		case 'l': {
-		    if ( uflag ) {
-			if ( *p == 'd' ) {
-			    d = va_arg( ap, unsigned int );
-			    sprintf( buf, "%u", d );
-			}
-			else {
-			    l = va_arg( ap, unsigned long );
-			    sprintf( buf, "%lu", l );
-			}
+		case 'd': {
+		    if ( lflag ) {
+			l = va_arg( ap, long );
+			sprintf( buf, "%ld", l );
 		    }
 		    else {
-			if ( *p == 'd' ) {
-			    d = va_arg( ap, int );
-			    sprintf( buf, "%d", d );
-			}
-			else {
-			    l = va_arg( ap, long );
-			    sprintf( buf, "%l", l );
-			}
+			d = va_arg( ap, int );
+			sprintf( buf, "%d", d );
 		    }
-		    *p++;
-		    len = strlen(buf);
-		    if ( len > (n-i) )
-			len = n-i;
-		    *q = '\0';
-		    strncat( q, buf, len );
-		    q += len;
-		    i += len;
-		    uflag = 0;
+                    len = strlen( buf );
+                    if ( len > (n-i) )
+                        len = n-i;
+                    *q = '\0';
+                    strncat( q, buf, len );
+                    q += len;
+                    i += len;
+		    lflag = 0;
 		    flag  = 0;
+		    p++;
+		    break;
+		}
+		case 'l': {
+		    /* next argument will be long */
+		    lflag = 1;
+		    p++;
 		    break;
 		}
 		case 'c': {
-		    if ( uflag )
-			c = va_arg( ap, unsigned char );
-		    else
-			c = va_arg( ap, char );
-		    uflag = 0;
+		    c = va_arg( ap, char );
+		    lflag = 0;
 		    flag  = 0;
 		    i++;
 		    *q++ = c;
@@ -647,6 +652,7 @@
 		    break;
 		}
 		case '%': {
+		    lflag = 0;
 		    flag  = 0;
 		    i++;
 		    *q++ = *p++;
@@ -655,7 +661,7 @@
 	    }
 	}
 	else {
-	    uflag = 0;
+	    lflag = 0;
 	    i++;
 	    *q++ = *p++;
 	}


-- 
leafnode-list@xxxxxxxxxxxxxxxxxxxxxxxxxxxx -- mailing list for leafnode
To unsubscribe, send mail with "unsubscribe" in the subject to the list