Re: [PATCH 1/3 v2] annotations: check for NULL position

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Mon, Jan 15, 2018 at 07:24:08PM +0100, Julia Lawall wrote:
> Check for NULL position and NULL filename.
> 
> Signed-off-by: Julia Lawall <Julia.Lawall@xxxxxxx>
> Signed-off-by: Frank Rowand <frank.rowand@xxxxxxxx>

Reviewed-by: David Gibson <david@xxxxxxxxxxxxxxxxxxxxx>

> ---
> 
> v2: Use xasprintf without result check.  Only use fname when it is defined.
> 
>  srcpos.c | 14 +++++++++++---
>  1 file changed, 11 insertions(+), 3 deletions(-)
> 
> diff --git a/srcpos.c b/srcpos.c
> index e8fced9..9067ba3 100644
> --- a/srcpos.c
> +++ b/srcpos.c
> @@ -250,12 +250,20 @@ srcpos_copy(struct srcpos *pos)
>  char *
>  srcpos_string(struct srcpos *pos)
>  {
> -	const char *fname = "<no-file>";
> +	const char *fname;
>  	char *pos_str;
>  
> -	if (pos->file && pos->file->name)
> -		fname = pos->file->name;
> +	if (!pos) {
> +		xasprintf(&pos_str, "<no-file>:<no-line>");
> +		return pos_str;
> +	}
>  
> +	if (!pos->file)
> +		fname = "<no-file>";
> +	else if (!pos->file->name)
> +		fname = "<no-filename>";
> +	else
> +		fname = pos->file->name;
>  
>  	if (pos->first_line != pos->last_line)
>  		xasprintf(&pos_str, "%s:%d.%d-%d.%d", fname,

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

Attachment: signature.asc
Description: PGP signature


[Index of Archives]     [Device Tree]     [Device Tree Spec]     [Linux Driver Backports]     [Video for Linux]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux