diff options
author | Glenn L McGrath | 2001-07-11 15:43:03 +0000 |
---|---|---|
committer | Glenn L McGrath | 2001-07-11 15:43:03 +0000 |
commit | 481d19b38e068e7db8459cb0e108f8049ce5919d (patch) | |
tree | 70aa7559c6b830ec0312fb7855826eea8e79ffa7 /libbb/read_package_field.c | |
parent | daf0b78e1a063fd90524d48aee4895c92a55f473 (diff) | |
download | busybox-481d19b38e068e7db8459cb0e108f8049ce5919d.zip busybox-481d19b38e068e7db8459cb0e108f8049ce5919d.tar.gz |
Fix bug where it wasnt returning the last line of a multiline field
Diffstat (limited to 'libbb/read_package_field.c')
-rw-r--r-- | libbb/read_package_field.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/libbb/read_package_field.c b/libbb/read_package_field.c index 246285f..3715230 100644 --- a/libbb/read_package_field.c +++ b/libbb/read_package_field.c @@ -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)); } |