]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: (samples/fromfile) properly handle return value from getline()
authorThomas Weißschuh <thomas@t-8ch.de>
Sun, 24 Dec 2023 11:38:53 +0000 (12:38 +0100)
committerThomas Weißschuh <thomas@t-8ch.de>
Sun, 31 Dec 2023 12:06:02 +0000 (13:06 +0100)
Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
libsmartcols/samples/fromfile.c

index f627df872d56f1403871146bdee9a80f631ed023..cf77cc47663493095fe68947bce938dd2d6e0b87 100644 (file)
@@ -44,7 +44,7 @@ static struct libscols_column *parse_column(const char *path)
 static int parse_column_data(FILE *f, struct libscols_table *tb, int col)
 {
        size_t len = 0, nlines = 0;
-       int i;
+       ssize_t i;
        char *str = NULL, *p;
 
        while ((i = getline(&str, &len, f)) != -1) {
@@ -64,7 +64,7 @@ static int parse_column_data(FILE *f, struct libscols_table *tb, int col)
                /* convert \x?? to real bytes */
                if (strstr(str, "\\x")) {
                        struct libscols_cell *ce = scols_line_get_cell(ln, col);
-                       size_t sz = len + 1;
+                       size_t sz = i + 1;
                        char *buf = xcalloc(1, sz);
 
                        sz = unhexmangle_to_buffer(str, buf, sz);