Fix: truncated value in fgetc() usage
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 15 Oct 2015 17:43:06 +0000 (13:43 -0400)
committerMichael Jeanson <mjeanson@efficios.com>
Fri, 16 Oct 2015 19:40:34 +0000 (15:40 -0400)
Reported by Coverity Scan:
CID 1327417:  API usage errors  (CHAR_IO)
Assigning the return value of "fgetc" to char "c" truncates
its value.

Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/compat/stdio.h

index 0301e2835269056cb79fa2a23f852eaaff6435fc..41d1df35037052cfbe6b39c2b8f0f23ec2683a4d 100644 (file)
@@ -84,9 +84,10 @@ ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream)
        }
        for (;;) {
                char c;
+               int ret;
 
-               c = fgetc(stream);
-               if (c == EOF) {
+               ret = fgetc(stream);
+               if (ret == EOF) {
                        if (ferror(stream)) {
                                /* ferror() is set, errno set by fgetc(). */
                                return -1;
@@ -95,6 +96,7 @@ ssize_t bt_getline(char **lineptr, size_t *n, FILE *stream)
                        found_eof = 1;
                        break;
                }
+               c = (char) ret;
                if (linelen == SSIZE_MAX) {
                        errno = EOVERFLOW;
                        return -1;
This page took 0.033207 seconds and 4 git commands to generate.