Subject: Re: tgetstr bug
To: None <tech-userlevel@netbsd.org>
From: Christos Zoulas <christos@astron.com>
List: tech-userlevel
Date: 12/18/2006 06:07:37
In article <em32vf$mi4$1@sea.gmane.org>,
Valeriy E. Ushakov <uwe@ptc.spbu.ru> wrote:
>Christos Zoulas <christos@astron.com> wrote:
>
>> In article <200612141505.51129.bruno@clisp.org>,
>> Bruno Haible  <bruno@clisp.org> wrote:
>>>tgetstr ("md", NULL) crashes on NetBSD. It's here:
>>>
>>>src/lib/libterm/termcap.c:
>>>
>>>char *
>>>t_getstr(struct tinfo *info, const char *id, char **area, size_t *limit)
>>>{
>>>...
>>>                _DIAGASSERT(limit != NULL);
>>>                *limit = i;                    <=====
>>>                free(s);
>>>                return NULL;
>>>...
>>>}
>>>
>>>Other systems support tgetstr ("md", NULL) without problems, and
>>>return the string in a statically allocated buffer.
>> 
>> The code that passes NULL is non-portable. According to the TOG:
>> 
>>    The tgetstr() function gets the string entry for id. If area is
>>    not a null pointer and does not point to a null pointer, tgetstr()
>>    copies the string entry into the buffer pointed to by *area and
>>    advances the variable pointed to by area to the first byte after
>>    the copy of the string entry.
>> 
>> By making tgetstr(id, NULL) work, we are encouraging non-portable
>> behavior.
>
>Hmm, why is that non-portable?  I read TOG text as that tgetstr
>returns the capability *and*, if area is not null, also copies the
>capability string into the area.
>
>Do I miss something?

No, you read it differently than I did. Anyway, it is simple enough
to fix, and I can see that this interpretation of the text is valid.

christos