Re: [PATCH 2/7] imd: string returned from imd_string_data should be const

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

 



Hi Sascha,

On Tue, Mar 29, 2016 at 10:50:49AM +0200, Sascha Hauer wrote:
> imd_string_data() returns the original data, so the string should be
> const.
> 
> Signed-off-by: Sascha Hauer <s.hauer@xxxxxxxxxxxxxx>
> ---
>  common/imd.c | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/common/imd.c b/common/imd.c
> index acaa23f..9bd1563 100644
> --- a/common/imd.c
> +++ b/common/imd.c
> @@ -193,7 +193,7 @@ static uint32_t imd_name_to_type(const char *name)
>  	return IMD_TYPE_INVALID;
>  }
>  
> -static char *imd_string_data(struct imd_header *imd, int index)
> +static const char *imd_string_data(struct imd_header *imd, int index)
>  {
>  	int i, total = 0, l = 0;
>  	int len = imd_read_length(imd);
> @@ -306,10 +306,15 @@ int imd_command(int argc, char *argv[])
>  		}
>  
>  		if (imd_is_string(type)) {
> -			if (strno >= 0)
> -				str = imd_string_data(imd, strno);
> -			else
> +			if (strno >= 0) {
> +				const char *s = imd_string_data(imd, strno);
> +				if (s)
> +					str = strdup(s);

The following code in the function doesn't free the string 'str' correctly. The
code is

                        if (strno < 0)
                                free(str);


> +				else
> +					str = NULL;
> +			} else {
>  				str = imd_concat_strings(imd);
> +			}
>  
>  			if (!str)
>  				return -ENODATA;
> -- 
> 2.7.0
> 
> 
> _______________________________________________
> barebox mailing list
> barebox@xxxxxxxxxxxxxxxxxxx
> http://lists.infradead.org/mailman/listinfo/barebox

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux