Message ID | 20210414141027.3494107-1-yochiang@google.com (mailing list archive) |
---|---|
State | Accepted |
Headers | show |
Series | secilc.c: Don't fail if input file is empty | expand |
On Wed, Apr 14, 2021 at 12:32 PM Yi-Yo Chiang <yochiang@google.com> wrote: > > fread(3) returns zero if |size| is zero. This confuses secilc, and > causes it to fail with a "Failure reading file" error, even though there > is no error. > > Add a shortcut that closes and skips an input file if file size is zero. > > Signed-off-by: Yi-Yo Chiang <yochiang@google.com> Acked-by: James Carter <jwcart2@gmail.com> > --- > secilc/secilc.c | 6 ++++++ > 1 file changed, 6 insertions(+) > > diff --git a/secilc/secilc.c b/secilc/secilc.c > index 186c5a73..9c78e425 100644 > --- a/secilc/secilc.c > +++ b/secilc/secilc.c > @@ -268,6 +268,12 @@ int main(int argc, char *argv[]) > } > file_size = filedata.st_size; > > + if (!file_size) { > + fclose(file); > + file = NULL; > + continue; > + } > + > buffer = malloc(file_size); > rc = fread(buffer, file_size, 1, file); > if (rc != 1) { > -- > 2.31.1.295.g9ea45b61b8-goog >
On Wed, Apr 14, 2021 at 3:18 PM James Carter <jwcart2@gmail.com> wrote: > > On Wed, Apr 14, 2021 at 12:32 PM Yi-Yo Chiang <yochiang@google.com> wrote: > > > > fread(3) returns zero if |size| is zero. This confuses secilc, and > > causes it to fail with a "Failure reading file" error, even though there > > is no error. > > > > Add a shortcut that closes and skips an input file if file size is zero. > > > > Signed-off-by: Yi-Yo Chiang <yochiang@google.com> > > Acked-by: James Carter <jwcart2@gmail.com> > Applied. Thanks, Jim > > --- > > secilc/secilc.c | 6 ++++++ > > 1 file changed, 6 insertions(+) > > > > diff --git a/secilc/secilc.c b/secilc/secilc.c > > index 186c5a73..9c78e425 100644 > > --- a/secilc/secilc.c > > +++ b/secilc/secilc.c > > @@ -268,6 +268,12 @@ int main(int argc, char *argv[]) > > } > > file_size = filedata.st_size; > > > > + if (!file_size) { > > + fclose(file); > > + file = NULL; > > + continue; > > + } > > + > > buffer = malloc(file_size); > > rc = fread(buffer, file_size, 1, file); > > if (rc != 1) { > > -- > > 2.31.1.295.g9ea45b61b8-goog > >
diff --git a/secilc/secilc.c b/secilc/secilc.c index 186c5a73..9c78e425 100644 --- a/secilc/secilc.c +++ b/secilc/secilc.c @@ -268,6 +268,12 @@ int main(int argc, char *argv[]) } file_size = filedata.st_size; + if (!file_size) { + fclose(file); + file = NULL; + continue; + } + buffer = malloc(file_size); rc = fread(buffer, file_size, 1, file); if (rc != 1) {
fread(3) returns zero if |size| is zero. This confuses secilc, and causes it to fail with a "Failure reading file" error, even though there is no error. Add a shortcut that closes and skips an input file if file size is zero. Signed-off-by: Yi-Yo Chiang <yochiang@google.com> --- secilc/secilc.c | 6 ++++++ 1 file changed, 6 insertions(+)