[Mesa-dev] [PATCH 3/4] nouveau: honor fread return value in the nouveau_compiler
Ilia Mirkin
imirkin at alum.mit.edu
Wed Mar 12 11:02:37 PDT 2014
On Wed, Mar 12, 2014 at 1:24 PM, Emil Velikov <emil.l.velikov at gmail.com> wrote:
> There is little point of continuing if fread returns zero, as it
> indicates that either the file is empty or cannot be read from.
> Bail out if fread returns zero after closing the file.
>
> Cc: Ilia Mirkin <imirkin at alum.mit.edu>
> Signed-off-by: Emil Velikov <emil.l.velikov at gmail.com>
Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
The fclose() you added serves no purpose (program is exiting anyways),
but it also doesn't hurt.
> ---
> src/gallium/drivers/nouveau/nouveau_compiler.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/src/gallium/drivers/nouveau/nouveau_compiler.c b/src/gallium/drivers/nouveau/nouveau_compiler.c
> index 5f1e35a..ac22035 100644
> --- a/src/gallium/drivers/nouveau/nouveau_compiler.c
> +++ b/src/gallium/drivers/nouveau/nouveau_compiler.c
> @@ -173,9 +173,9 @@ main(int argc, char *argv[])
> return 1;
> }
>
> - fread(text, 1, sizeof(text), f);
> - if (ferror(f)) {
> + if (!fread(text, 1, sizeof(text), f) || ferror(f)) {
> _debug_printf("Error reading file '%s'\n", filename);
> + fclose(f);
> return 1;
> }
> fclose(f);
> --
> 1.9.0
>
More information about the mesa-dev
mailing list