Fix bug where it wasnt returning the last line of a multiline field
authorGlenn L McGrath <bug1@ihug.co.nz>
Wed, 11 Jul 2001 15:43:03 +0000 (15:43 -0000)
committerGlenn L McGrath <bug1@ihug.co.nz>
Wed, 11 Jul 2001 15:43:03 +0000 (15:43 -0000)
libbb/read_package_field.c

index 246285f8ec4ada00a921c55a6848ebd890c27825..3715230feab3a003b3766867e1715a1fed605c38 100644 (file)
@@ -7,24 +7,21 @@
  */
 extern char *read_package_field(const char *package_buffer)
 {
-       char *field = NULL;
        int field_length = 0;   
        int buffer_length = 0;
 
+       if (package_buffer == NULL) {
+               return(NULL);
+       }
        buffer_length = strlen(package_buffer);
-
-       while ((field = strchr(&package_buffer[field_length], '\n')) != NULL) {
-               field_length = buffer_length - strlen(field);
+       field_length = strcspn(package_buffer, "\n");
+       while (field_length < buffer_length) {
                if (package_buffer[field_length + 1] != ' ') {
-                       break;
-               } else {
-                       field_length++;
-               }               
-       }
-       if (field_length == 0) {
-               return(NULL);
-       } else {
-               return(xstrndup(package_buffer, field_length));
+                       return(xstrndup(package_buffer, field_length));
+               }
+               field_length++;
+               field_length += strcspn(&package_buffer[field_length], "\n");
        }
+       return(xstrdup(package_buffer));
 }