diff mbox series

[2/3] tokenize: check if string is not NULL

Message ID 20181026152632.30318-3-ben.dooks@codethink.co.uk (mailing list archive)
State Superseded, archived
Headers show
Series [1/3] initial parsing of __attribute__((format)) | expand

Commit Message

Ben Dooks Oct. 26, 2018, 3:26 p.m. UTC
---
 tokenize.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Luc Van Oostenryck Oct. 26, 2018, 9:33 p.m. UTC | #1
On Fri, Oct 26, 2018 at 04:26:31PM +0100, Ben Dooks wrote:
> ---
>  tokenize.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/tokenize.c b/tokenize.c
> index 99b9580..c32f8c7 100644
> --- a/tokenize.c
> +++ b/tokenize.c
> @@ -124,7 +124,7 @@ const char *show_string(const struct string *string)
>  	char *ptr;
>  	int i;
>  
> -	if (!string->length)
> +	if (!string || !string->length)
>  		return "<bad_string>";

I don't understand this change. What about a zero-length string ("")?

-- Luc
Ben Dooks Oct. 29, 2018, 1:40 p.m. UTC | #2
On 26/10/18 22:33, Luc Van Oostenryck wrote:
> On Fri, Oct 26, 2018 at 04:26:31PM +0100, Ben Dooks wrote:
>> ---
>>   tokenize.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/tokenize.c b/tokenize.c
>> index 99b9580..c32f8c7 100644
>> --- a/tokenize.c
>> +++ b/tokenize.c
>> @@ -124,7 +124,7 @@ const char *show_string(const struct string *string)
>>   	char *ptr;
>>   	int i;
>>   
>> -	if (!string->length)
>> +	if (!string || !string->length)
>>   		return "<bad_string>";
> 
> I don't understand this change. What about a zero-length string ("")?


The original checks for string->length but not if the string itself
was NULL. I've eliminated the original mistake that triggered this.
Luc Van Oostenryck Oct. 29, 2018, 1:55 p.m. UTC | #3
On Mon, Oct 29, 2018 at 01:40:06PM +0000, Ben Dooks wrote:
> On 26/10/18 22:33, Luc Van Oostenryck wrote:
> > On Fri, Oct 26, 2018 at 04:26:31PM +0100, Ben Dooks wrote:
> > > ---
> > >   tokenize.c | 2 +-
> > >   1 file changed, 1 insertion(+), 1 deletion(-)
> > > 
> > > diff --git a/tokenize.c b/tokenize.c
> > > index 99b9580..c32f8c7 100644
> > > --- a/tokenize.c
> > > +++ b/tokenize.c
> > > @@ -124,7 +124,7 @@ const char *show_string(const struct string *string)
> > >   	char *ptr;
> > >   	int i;
> > > -	if (!string->length)
> > > +	if (!string || !string->length)
> > >   		return "<bad_string>";
> > 
> > I don't understand this change. What about a zero-length string ("")?
> 
> 
> The original checks for string->length but not if the string itself
> was NULL. I've eliminated the original mistake that triggered this.

Oh yes, sorry. I didn't noticed that the original test checked the length
and not the pointer.

I'll investigate why the length was tested.

Have you an example/testcase where it crashed?


Kind regards,
-- Luc
Ben Dooks Oct. 29, 2018, 2:11 p.m. UTC | #4
On 29/10/18 13:55, Luc Van Oostenryck wrote:
> On Mon, Oct 29, 2018 at 01:40:06PM +0000, Ben Dooks wrote:
>> On 26/10/18 22:33, Luc Van Oostenryck wrote:
>>> On Fri, Oct 26, 2018 at 04:26:31PM +0100, Ben Dooks wrote:
>>>> ---
>>>>    tokenize.c | 2 +-
>>>>    1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/tokenize.c b/tokenize.c
>>>> index 99b9580..c32f8c7 100644
>>>> --- a/tokenize.c
>>>> +++ b/tokenize.c
>>>> @@ -124,7 +124,7 @@ const char *show_string(const struct string *string)
>>>>    	char *ptr;
>>>>    	int i;
>>>> -	if (!string->length)
>>>> +	if (!string || !string->length)
>>>>    		return "<bad_string>";
>>>
>>> I don't understand this change. What about a zero-length string ("")?
>>
>>
>> The original checks for string->length but not if the string itself
>> was NULL. I've eliminated the original mistake that triggered this.
> 
> Oh yes, sorry. I didn't noticed that the original test checked the length
> and not the pointer.
> 
> I'll investigate why the length was tested.
> 
> Have you an example/testcase where it crashed?

I was using it in earlier code, but I removed the call to show_string
I think (debugging).
diff mbox series

Patch

diff --git a/tokenize.c b/tokenize.c
index 99b9580..c32f8c7 100644
--- a/tokenize.c
+++ b/tokenize.c
@@ -124,7 +124,7 @@  const char *show_string(const struct string *string)
 	char *ptr;
 	int i;
 
-	if (!string->length)
+	if (!string || !string->length)
 		return "<bad_string>";
 	ptr = buffer;
 	*ptr++ = '"';