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

pkg_info bug



L.S.

When making a port a discovered that COMMENT has to end with a lf, or
else pkg_info will print the info for the next package on the same line.
I don't like this as COMMENT is a single line, so I checked
/usr/src/usr.sbin/pkg_install/info/show.c:


At line 97 is this code:

        if (fgets(line, MAXINDEXSIZE+1, fp)) {
                if (line[MAXINDEXSIZE-1] != '\n') {
                        line[MAXINDEXSIZE] = '\n';
                }
                line[MAXINDEXSIZE+1] = 0;
                (void) fputs(line, stdout);
        }

This should be:

        if (fgets(line, MAXINDEXSIZE+1, fp)) {
                int  line_length = strlen(line);

                if (line[line_length-1] != '\n') {
                        line[line_length] = '\n';
                        line[line_length+1] = 0;
                }
                (void) fputs(line, stdout);
        }

For convenience I've attached a diff.

(Note: I'm using a mostly stock obsd 2.4 i386)

-- 

Wouter

GSI (pcm/midi/cd/mixer), GGI, descent: http://www.cistron.nl/~wouters/
--- show.c.orig	Sun Mar  7 21:41:46 1999
+++ show.c	Sun Mar  7 22:27:30 1999
@@ -95,10 +95,12 @@
 		return;
 	}
 	if (fgets(line, MAXINDEXSIZE+1, fp)) {
-		if (line[MAXINDEXSIZE-1] != '\n') {
-			line[MAXINDEXSIZE] = '\n';
+		int  line_length = strlen(line);
+
+		if (line[line_length-1] != '\n') {
+			line[line_length] = '\n';
+			line[line_length+1] = 0;
 		}
-		line[MAXINDEXSIZE+1] = 0;
 		(void) fputs(line, stdout);
 	}
 	(void) fclose(fp);