[SDL] Strange code in SDL_SendKeyboardText

Jjgod Jiang gzjjgod at gmail.com
Thu May 13 18:01:00 PDT 2010


Hi Mason,

On Fri, May 14, 2010 at 2:27 AM, Mason Wheeler <masonwheeler at yahoo.com> wrote:
> I've been tracking down an access violation I get when sending keyboard
> input to an SDL window, and I tracked it to SDL_SendKeyboardText in
> SDL_keyboard.c.  Specifically, this block:
>
>         event.text.windowID = keyboard->focus ? keyboard->focus->id : 0;
>         event.text.which = (Uint8) index;
>         SDL_strlcpy(event.text.text, text, SDL_arraysize(event.text.text));
>         event.text.windowID = keyboard->focus->id;
>
> What's going on here?  First, we explicitly contemplate the possibility that
> keyboard->focus might be NULL and account for it.  Then we fill in a few
> other fields, then we repeat the earlier assignment, without the NULL check
> and things explode because it's null.
>
> No relevant comments, so I can't do much to read the original coder's mind.
> Is this just something that someone replaced and forgot to take out?  I
> think that last line should be removed.

First of all, you are right, there shouldn't be another assignment.

Secondly, the current code seems already checked the pointer in the
second assignment [1].

Anyway, the second assignment should be removed.

- Jiang

[1] http://hg.libsdl.org/SDL/file/fa77a6429698/src/events/SDL_keyboard.c



More information about the SDL mailing list