Skip to content

Commit 49ac23f

Browse files
committed
Make the PR #610 code less ugly
1 parent 5c3fa23 commit 49ac23f

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

src/util_uri.c

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -734,23 +734,15 @@ static int read_from_file(UTIL_CTX *ctx,
734734
return 0;
735735
}
736736
if (BIO_gets(fp, txt, (int)*field_len + 1) > 0) {
737-
*field_len = strlen(txt);
737+
size_t len = strlen(txt);
738+
739+
while (len > 0 && (txt[len - 1] == '\n' || txt[len - 1] == '\r'))
740+
len--;
741+
memcpy(field, txt, len);
742+
*field_len = len;
738743
} else {
739744
*field_len = 0;
740-
goto done;
741-
}
742-
743-
/* files may contain trailing newlines, remove them */
744-
while (*field_len > 0) {
745-
if (txt[*field_len - 1] == '\n' || txt[*field_len - 1] == '\r') {
746-
(*field_len)--;
747-
} else {
748-
break;
749-
}
750745
}
751-
memcpy(field, txt, *field_len);
752-
753-
done:
754746
OPENSSL_free(txt);
755747

756748
BIO_free(fp);

0 commit comments

Comments
 (0)