[Mesa-dev] [PATCH] util/disk_cache: error check asprintf()

Eric Engestrom eric.engestrom at imgtec.com
Thu Feb 9 11:52:58 UTC 2017


Reviewed-by: Eric Engestrom <eric.engestrom at imgtec.com>

On Thursday, 2017-02-09 22:42:51 +1100, Timothy Arceri wrote:
> ---
>  src/util/disk_cache.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/src/util/disk_cache.c b/src/util/disk_cache.c
> index edfff73..22a856e 100644
> --- a/src/util/disk_cache.c
> +++ b/src/util/disk_cache.c
> @@ -403,7 +403,9 @@ get_cache_file(struct disk_cache *cache, cache_key key)
>     char *filename;
>  
>     _mesa_sha1_format(buf, key);
> -   asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0], buf[1], buf + 2);
> +   if (asprintf(&filename, "%s/%c%c/%s", cache->path, buf[0],
> +                buf[1], buf + 2) == -1)
> +      return NULL;
>  
>     return filename;
>  }
> @@ -420,9 +422,10 @@ make_cache_file_directory(struct disk_cache *cache, cache_key key)
>     char buf[41];
>  
>     _mesa_sha1_format(buf, key);
> -   asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]);
> -   mkdir_if_needed(dir);
> +   if (asprintf(&dir, "%s/%c%c", cache->path, buf[0], buf[1]) == -1)
> +      return;
>  
> +   mkdir_if_needed(dir);
>     free(dir);
>  }
>  
> @@ -654,8 +657,7 @@ disk_cache_put(struct disk_cache *cache,
>      * final destination filename, (to prevent any readers from seeing
>      * a partially written file).
>      */
> -   asprintf(&filename_tmp, "%s.tmp", filename);
> -   if (filename_tmp == NULL)
> +   if (asprintf(&filename_tmp, "%s.tmp", filename) == -1)
>        goto done;
>  
>     fd = open(filename_tmp, O_WRONLY | O_CLOEXEC | O_CREAT, 0644);
> -- 
> 2.9.3
> 


More information about the mesa-dev mailing list