use the new constant `TINYSTR_LEN` in place of `sizeof(tinystr)` leftovers
Signed-off-by: NaitLee <naitli@foxmail.com>
- // non-ascii keys are Unicode codepoints, so give the character
+ // non-ascii keys are Unicode codepoints, so give the character if it's valid;
+ // error message have more than one character, don't allow it
ch = u8_getnchar(str, &str, 3);
ch = u8_getnchar(str, &str, 3);
- return ch == 0 ? -1 : (int)ch;
+ return (ch == 0 || *str != 0) ? -1 : (int)ch;
{
Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false);
if (j == 0)
{
Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false);
if (j == 0)
- Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf);
+ Con_Printf("^2%s ^7= \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf);
- Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf);
+ Con_Printf("^3bindmap %d: ^2%s ^7= \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf);
{
Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind
if (j == 0)
{
Cmd_QuoteString(bindbuf, sizeof(bindbuf), p, "\"\\", false); // don't need to escape $ because cvars are not expanded inside bind
if (j == 0)
- FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf);
+ FS_Printf(f, "bind %s \"%s\"\n", Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf);
- FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, sizeof(tinystr)), bindbuf);
+ FS_Printf(f, "in_bind %d %s \"%s\"\n", j, Key_KeynumToString (i, tinystr, TINYSTR_LEN), bindbuf);
{
if (j > 0)
strlcat(keystring, " or ", sizeof(keystring));
{
if (j > 0)
strlcat(keystring, " or ", sizeof(keystring));
- strlcat(keystring, Key_KeynumToString (keys[j], tinystr, sizeof(tinystr)), sizeof(keystring));
+ strlcat(keystring, Key_KeynumToString (keys[j], tinystr, TINYSTR_LEN), sizeof(keystring));
- dpsnprintf(line, sizeof(line), "bind \"%s\" \"%s\"\n", Key_KeynumToString(k, tinystr, sizeof(tinystr)), bindnames[keys_cursor][0]);
+ dpsnprintf(line, sizeof(line), "bind \"%s\" \"%s\"\n", Key_KeynumToString(k, tinystr, TINYSTR_LEN), bindnames[keys_cursor][0]);
Cbuf_InsertText (cmd, line);
}
Cbuf_InsertText (cmd, line);
}
char tinystr[TINYSTR_LEN];
VM_SAFEPARMCOUNT(1, VM_keynumtostring);
char tinystr[TINYSTR_LEN];
VM_SAFEPARMCOUNT(1, VM_keynumtostring);
- PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0), tinystr, sizeof(tinystr)));
+ PRVM_G_INT(OFS_RETURN) = PRVM_SetTempString(prog, Key_KeynumToString((int)PRVM_G_FLOAT(OFS_PARM0), tinystr, TINYSTR_LEN));
switch(sdlkey)
{
// sdlkey can be Unicode codepoint for non-ascii keys, which are valid
switch(sdlkey)
{
// sdlkey can be Unicode codepoint for non-ascii keys, which are valid
- default: return sdlkey;
+ default: return sdlkey & SDLK_SCANCODE_MASK ? 0 : sdlkey;
// case SDLK_UNKNOWN: return K_UNKNOWN;
case SDLK_RETURN: return K_ENTER;
case SDLK_ESCAPE: return K_ESCAPE;
// case SDLK_UNKNOWN: return K_UNKNOWN;
case SDLK_RETURN: return K_ENTER;
case SDLK_ESCAPE: return K_ESCAPE;