Mercurial > vim
comparison src/option.c @ 30409:aea53db7eeec v9.0.0540
patch 9.0.0540: assigning stack variable to argument confuses Coverity
Commit: https://github.com/vim/vim/commit/6f98114e4a5db3917c4f9d2fec09e11b4b0d0be5
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Sep 22 12:48:58 2022 +0100
patch 9.0.0540: assigning stack variable to argument confuses Coverity
Problem: Assigning stack variable to argument confuses Coverity.
Solution: Use a local pointer, also makes the code simpler.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 22 Sep 2022 14:00:08 +0200 |
parents | 42d592459521 |
children | 6a1862bfb280 |
comparison
equal
deleted
inserted
replaced
30408:6e69efa182cb | 30409:aea53db7eeec |
---|---|
1218 */ | 1218 */ |
1219 static int | 1219 static int |
1220 do_set_string( | 1220 do_set_string( |
1221 int opt_idx, | 1221 int opt_idx, |
1222 int opt_flags, | 1222 int opt_flags, |
1223 char_u **arg, | 1223 char_u **argp, |
1224 int nextchar, | 1224 int nextchar, |
1225 set_op_T op_arg, | 1225 set_op_T op_arg, |
1226 int flags, | 1226 int flags, |
1227 int cp_val, | 1227 int cp_val, |
1228 char_u *varp_arg, | 1228 char_u *varp_arg, |
1229 char *errbuf, | 1229 char *errbuf, |
1230 int *value_checked, | 1230 int *value_checked, |
1231 char **errmsg) | 1231 char **errmsg) |
1232 { | 1232 { |
1233 char_u *arg = *argp; | |
1233 set_op_T op = op_arg; | 1234 set_op_T op = op_arg; |
1234 char_u *varp = varp_arg; | 1235 char_u *varp = varp_arg; |
1235 char_u *save_arg = NULL; | 1236 char_u *save_arg = NULL; |
1236 char_u *s = NULL; | 1237 char_u *s = NULL; |
1237 char_u *oldval = NULL; // previous value if *varp | 1238 char_u *oldval = NULL; // previous value if *varp |
1315 newval = vim_strsave(*(char_u **)get_varp_scope( | 1316 newval = vim_strsave(*(char_u **)get_varp_scope( |
1316 &(options[opt_idx]), OPT_GLOBAL)); | 1317 &(options[opt_idx]), OPT_GLOBAL)); |
1317 } | 1318 } |
1318 else | 1319 else |
1319 { | 1320 { |
1320 ++*arg; // jump to after the '=' or ':' | 1321 ++arg; // jump to after the '=' or ':' |
1321 | 1322 |
1322 /* | 1323 /* |
1323 * Set 'keywordprg' to ":help" if an empty | 1324 * Set 'keywordprg' to ":help" if an empty |
1324 * value was passed to :set by the user. | 1325 * value was passed to :set by the user. |
1325 * Misuse errbuf[] for the resulting string. | 1326 * Misuse errbuf[] for the resulting string. |
1326 */ | 1327 */ |
1327 if (varp == (char_u *)&p_kp && (**arg == NUL || **arg == ' ')) | 1328 if (varp == (char_u *)&p_kp && (*arg == NUL || *arg == ' ')) |
1328 { | 1329 { |
1329 STRCPY(errbuf, ":help"); | 1330 STRCPY(errbuf, ":help"); |
1330 save_arg = *arg; | 1331 save_arg = arg; |
1331 *arg = (char_u *)errbuf; | 1332 arg = (char_u *)errbuf; |
1332 } | 1333 } |
1333 /* | 1334 /* |
1334 * Convert 'backspace' number to string, for | 1335 * Convert 'backspace' number to string, for |
1335 * adding, prepending and removing string. | 1336 * adding, prepending and removing string. |
1336 */ | 1337 */ |
1366 } | 1367 } |
1367 /* | 1368 /* |
1368 * Convert 'whichwrap' number to string, for backwards compatibility | 1369 * Convert 'whichwrap' number to string, for backwards compatibility |
1369 * with Vim 3.0. | 1370 * with Vim 3.0. |
1370 */ | 1371 */ |
1371 else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(**arg)) | 1372 else if (varp == (char_u *)&p_ww && VIM_ISDIGIT(*arg)) |
1372 { | 1373 { |
1373 *whichwrap = NUL; | 1374 *whichwrap = NUL; |
1374 int i = getdigits(arg); | 1375 int i = getdigits(&arg); |
1375 if (i & 1) | 1376 if (i & 1) |
1376 STRCAT(whichwrap, "b,"); | 1377 STRCAT(whichwrap, "b,"); |
1377 if (i & 2) | 1378 if (i & 2) |
1378 STRCAT(whichwrap, "s,"); | 1379 STRCAT(whichwrap, "s,"); |
1379 if (i & 4) | 1380 if (i & 4) |
1382 STRCAT(whichwrap, "<,>,"); | 1383 STRCAT(whichwrap, "<,>,"); |
1383 if (i & 16) | 1384 if (i & 16) |
1384 STRCAT(whichwrap, "[,],"); | 1385 STRCAT(whichwrap, "[,],"); |
1385 if (*whichwrap != NUL) // remove trailing , | 1386 if (*whichwrap != NUL) // remove trailing , |
1386 whichwrap[STRLEN(whichwrap) - 1] = NUL; | 1387 whichwrap[STRLEN(whichwrap) - 1] = NUL; |
1387 save_arg = *arg; | 1388 save_arg = arg; |
1388 *arg = (char_u *)whichwrap; | 1389 arg = (char_u *)whichwrap; |
1389 } | 1390 } |
1390 /* | 1391 /* |
1391 * Remove '>' before 'dir' and 'bdir', for backwards compatibility with | 1392 * Remove '>' before 'dir' and 'bdir', for backwards compatibility with |
1392 * version 3.0 | 1393 * version 3.0 |
1393 */ | 1394 */ |
1394 else if ( **arg == '>' && (varp == (char_u *)&p_dir | 1395 else if (*arg == '>' && (varp == (char_u *)&p_dir |
1395 || varp == (char_u *)&p_bdir)) | 1396 || varp == (char_u *)&p_bdir)) |
1396 ++*arg; | 1397 ++arg; |
1397 | 1398 |
1398 /* | 1399 /* |
1399 * Copy the new string into allocated memory. | 1400 * Copy the new string into allocated memory. |
1400 * Can't use set_string_option_direct(), because we need to remove the | 1401 * Can't use set_string_option_direct(), because we need to remove the |
1401 * backslashes. | 1402 * backslashes. |
1402 */ | 1403 */ |
1403 // get a bit too much | 1404 // get a bit too much |
1404 newlen = (unsigned)STRLEN(*arg) + 1; | 1405 newlen = (unsigned)STRLEN(arg) + 1; |
1405 if (op != OP_NONE) | 1406 if (op != OP_NONE) |
1406 newlen += (unsigned)STRLEN(origval) + 1; | 1407 newlen += (unsigned)STRLEN(origval) + 1; |
1407 newval = alloc(newlen); | 1408 newval = alloc(newlen); |
1408 if (newval == NULL) // out of mem, don't change | 1409 if (newval == NULL) // out of mem, don't change |
1409 return FAIL; | 1410 return FAIL; |
1414 * For MS-DOS and WIN32 backslashes before normal file name characters | 1415 * For MS-DOS and WIN32 backslashes before normal file name characters |
1415 * are not removed, and keep backslash at start, for "\\machine\path", | 1416 * are not removed, and keep backslash at start, for "\\machine\path", |
1416 * but do remove it for "\\\\machine\\path". | 1417 * but do remove it for "\\\\machine\\path". |
1417 * The reverse is found in ExpandOldSetting(). | 1418 * The reverse is found in ExpandOldSetting(). |
1418 */ | 1419 */ |
1419 while (**arg && !VIM_ISWHITE(**arg)) | 1420 while (*arg && !VIM_ISWHITE(*arg)) |
1420 { | 1421 { |
1421 int i; | 1422 int i; |
1422 | 1423 |
1423 if (**arg == '\\' && (*arg)[1] != NUL | 1424 if (*arg == '\\' && arg[1] != NUL |
1424 #ifdef BACKSLASH_IN_FILENAME | 1425 #ifdef BACKSLASH_IN_FILENAME |
1425 && !((flags & P_EXPAND) | 1426 && !((flags & P_EXPAND) |
1426 && vim_isfilec((*arg)[1]) | 1427 && vim_isfilec(arg[1]) |
1427 && !VIM_ISWHITE((*arg)[1]) | 1428 && !VIM_ISWHITE(arg[1]) |
1428 && ((*arg)[1] != '\\' | 1429 && (arg[1] != '\\' |
1429 || (s == newval && (*arg)[2] != '\\'))) | 1430 || (s == newval && arg[2] != '\\'))) |
1430 #endif | 1431 #endif |
1431 ) | 1432 ) |
1432 ++*arg; // remove backslash | 1433 ++arg; // remove backslash |
1433 if (has_mbyte && (i = (*mb_ptr2len)(*arg)) > 1) | 1434 if (has_mbyte && (i = (*mb_ptr2len)(arg)) > 1) |
1434 { | 1435 { |
1435 // copy multibyte char | 1436 // copy multibyte char |
1436 mch_memmove(s, *arg, (size_t)i); | 1437 mch_memmove(s, arg, (size_t)i); |
1437 *arg += i; | 1438 arg += i; |
1438 s += i; | 1439 s += i; |
1439 } | 1440 } |
1440 else | 1441 else |
1441 *s++ = *(*arg)++; | 1442 *s++ = *arg++; |
1442 } | 1443 } |
1443 *s = NUL; | 1444 *s = NUL; |
1444 | 1445 |
1445 /* | 1446 /* |
1446 * Expand environment variables and ~. | 1447 * Expand environment variables and ~. |
1563 ++s; | 1564 ++s; |
1564 } | 1565 } |
1565 } | 1566 } |
1566 | 1567 |
1567 if (save_arg != NULL) // number for 'whichwrap' | 1568 if (save_arg != NULL) // number for 'whichwrap' |
1568 *arg = save_arg; | 1569 arg = save_arg; |
1569 } | 1570 } |
1570 | 1571 |
1571 /* | 1572 /* |
1572 * Set the new value. | 1573 * Set the new value. |
1573 */ | 1574 */ |
1625 vim_free(saved_origval_l); | 1626 vim_free(saved_origval_l); |
1626 vim_free(saved_origval_g); | 1627 vim_free(saved_origval_g); |
1627 vim_free(saved_newval); | 1628 vim_free(saved_newval); |
1628 #endif | 1629 #endif |
1629 | 1630 |
1631 *argp = arg; | |
1630 return *errmsg == NULL ? OK : FAIL; | 1632 return *errmsg == NULL ? OK : FAIL; |
1631 } | 1633 } |
1632 | 1634 |
1633 /* | 1635 /* |
1634 * Parse 'arg' for option settings. | 1636 * Parse 'arg' for option settings. |