Skip to content

Commit 8152566

Browse files
Fix NEGATIVE_RETURNS Coverity issue
lib/pkg_editor/src/pkg_editor.c:500:3: Type: Improper use of negative value (NEGATIVE_RETURNS) lib/pkg_editor/src/pkg_editor.c:489:3: 1. path: Condition "f == NULL", taking false branch. lib/pkg_editor/src/pkg_editor.c:496:3: 2. negative_return_fn: Function "ftell(f)" returns a negative number. lib/pkg_editor/src/pkg_editor.c:496:3: 3. assign: Assigning: "file_size" = "ftell(f)". lib/pkg_editor/src/pkg_editor.c:500:3: 4. negative_returns: "file_size" is passed to a parameter that cannot be negative. lib/pkg_editor/src/pkg_editor.c:461:3: 4.1. path: Condition "buf == NULL", taking false branch. lib/pkg_editor/src/pkg_editor.c:459:60: 4.2. sizet: "size" is a size_t parameter.
1 parent 8085c99 commit 8152566

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/pkg_editor/src/pkg_editor.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,13 +493,13 @@ static char *read_file_into_buffer(struct acl_pkg_file *pkg,
493493

494494
// get file size
495495
fseek(f, 0, SEEK_END);
496-
long ftell_return = ftell(f);
496+
const long ftell_return = ftell(f);
497497
if (ftell_return < 0) {
498498
fprintf(stderr, "Couldn't determine size of file %s\n", in_file);
499499
fclose(f);
500500
return NULL;
501501
}
502-
file_size = ftell_return;
502+
const size_t file_size = (size_t)ftell_return;
503503
rewind(f);
504504

505505
// slurp the whole file into allocated buf

0 commit comments

Comments
 (0)