|
From: | Johannes Altmanninger |
Subject: | Re: [RP] select patch |
Date: | Thu, 19 Jun 2014 20:12:35 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
On 06/19/2014 03:47 PM, Bernhard R. Link wrote:
* Jeff Abrahamson <address@hidden> [140618 20:52]:- Using raw strcmp() isn't a very good idea -- if one of the strings is not null-terminated, you introduce a subtle bug. Prefer instead strncmp() and strnlen(). This requires defining some reasonable upper limit on window names, of course.I have to disagree quite vehemently here. Either things are null-terminated or they are not. If they are then introducing a limit where there is not can only produce bugs (subtle and non-subtle). If they are not then most of the time things starting with str* are usually the wrong tools anyway. Bernhard R. Link
In this case strncmp() is practical because I do not have towrite two different blocks for full match and prefix match (atleast until I have figured out function pointers). strncmp() seems to be safe with a reasonable limit (it stops comparing after n bytes as far as I know)
strnlen() seems unnecessary as the whole program uses strlen()
[Prev in Thread] | Current Thread | [Next in Thread] |