comparison src/gui_xim.c @ 34074:1629cc65d78d v9.1.0006

patch 9.1.0006: is*() and to*() function may be unsafe Commit: https://github.com/vim/vim/commit/184f71cc6868a240dc872ed2852542bbc1d43e28 Author: Keith Thompson <Keith.S.Thompson@gmail.com> Date: Thu Jan 4 21:19:04 2024 +0100 patch 9.1.0006: is*() and to*() function may be unsafe Problem: is*() and to*() function may be unsafe Solution: Add SAFE_* macros and start using those instead (Keith Thompson) Use SAFE_() macros for is*() and to*() functions The standard is*() and to*() functions declared in <ctype.h> have undefined behavior for negative arguments other than EOF. If plain char is signed, passing an unchecked value from argv for from user input to one of these functions has undefined behavior. Solution: Add SAFE_*() macros that cast the argument to unsigned char. Most implementations behave sanely for negative arguments, and most character values in practice are non-negative, but it's still best to avoid undefined behavior. The change from #13347 has been omitted, as this has already been separately fixed in commit ac709e2fc0db6d31abb7da96f743c40956b60c3a (v9.0.2054) fixes: #13332 closes: #13347 Signed-off-by: Keith Thompson <Keith.S.Thompson@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 04 Jan 2024 21:30:04 +0100
parents 4545f58c8490
children a0a4a774117b
comparison
equal deleted inserted replaced
34073:7d9c9731e78e 34074:1629cc65d78d
1469 s = (char *)skipwhite((char_u *)s); 1469 s = (char *)skipwhite((char_u *)s);
1470 if (*s == NUL) 1470 if (*s == NUL)
1471 break; 1471 break;
1472 if ((ns = end = strchr(s, ',')) == NULL) 1472 if ((ns = end = strchr(s, ',')) == NULL)
1473 end = s + strlen(s); 1473 end = s + strlen(s);
1474 while (isspace(((char_u *)end)[-1])) 1474 while (SAFE_isspace(end[-1]))
1475 end--; 1475 end--;
1476 *end = NUL; 1476 *end = NUL;
1477 1477
1478 if (strlen(s) <= IMLEN_MAX) 1478 if (strlen(s) <= IMLEN_MAX)
1479 { 1479 {
1531 1531
1532 found = False; 1532 found = False;
1533 strcpy(tmp, gui.rsrc_preedit_type_name); 1533 strcpy(tmp, gui.rsrc_preedit_type_name);
1534 for (s = tmp; s && !found; ) 1534 for (s = tmp; s && !found; )
1535 { 1535 {
1536 while (*s && isspace((unsigned char)*s)) 1536 while (*s && SAFE_isspace(*s))
1537 s++; 1537 s++;
1538 if (!*s) 1538 if (!*s)
1539 break; 1539 break;
1540 if ((ns = end = strchr(s, ',')) != 0) 1540 if ((ns = end = strchr(s, ',')) != 0)
1541 ns++; 1541 ns++;
1542 else 1542 else
1543 end = s + strlen(s); 1543 end = s + strlen(s);
1544 while (isspace((unsigned char)*end)) 1544 while (SAFE_isspace(*end))
1545 end--; 1545 end--;
1546 *end = '\0'; 1546 *end = '\0';
1547 1547
1548 if (!strcmp(s, "OverTheSpot")) 1548 if (!strcmp(s, "OverTheSpot"))
1549 this_input_style = (XIMPreeditPosition | XIMStatusArea); 1549 this_input_style = (XIMPreeditPosition | XIMStatusArea);