Mercurial > vim
comparison src/strings.c @ 31624:d605a50e7623 v9.0.1144
patch 9.0.1144: reading beyond text
Commit: https://github.com/vim/vim/commit/c32949b0779106ed5710ae3bffc5053e49083ab4
Author: Bram Moolenaar <Bram@vim.org>
Date: Wed Jan 4 15:56:51 2023 +0000
patch 9.0.1144: reading beyond text
Problem: Reading beyond text.
Solution: Add strlen_maxlen() and use it.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Wed, 04 Jan 2023 17:00:05 +0100 |
parents | b3de17181c19 |
children | 543153d582d5 |
comparison
equal
deleted
inserted
replaced
31623:f061953e1618 | 31624:d605a50e7623 |
---|---|
523 } | 523 } |
524 else | 524 else |
525 mch_memmove(to + tolen, from, fromlen + 1); | 525 mch_memmove(to + tolen, from, fromlen + 1); |
526 } | 526 } |
527 | 527 |
528 /* | |
529 * A version of strlen() that has a maximum length. | |
530 */ | |
531 size_t | |
532 vim_strlen_maxlen(char *s, size_t maxlen) | |
533 { | |
534 size_t i; | |
535 for (i = 0; i < maxlen; ++i) | |
536 if (s[i] == NUL) | |
537 break; | |
538 return i; | |
539 } | |
540 | |
528 #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO) | 541 #if (!defined(HAVE_STRCASECMP) && !defined(HAVE_STRICMP)) || defined(PROTO) |
529 /* | 542 /* |
530 * Compare two strings, ignoring case, using current locale. | 543 * Compare two strings, ignoring case, using current locale. |
531 * Doesn't work for multi-byte characters. | 544 * Doesn't work for multi-byte characters. |
532 * return 0 for match, < 0 for smaller, > 0 for bigger | 545 * return 0 for match, < 0 for smaller, > 0 for bigger |
580 * Search for first occurrence of "c" in "string". | 593 * Search for first occurrence of "c" in "string". |
581 * Version of strchr() that handles unsigned char strings with characters from | 594 * Version of strchr() that handles unsigned char strings with characters from |
582 * 128 to 255 correctly. It also doesn't return a pointer to the NUL at the | 595 * 128 to 255 correctly. It also doesn't return a pointer to the NUL at the |
583 * end of the string. | 596 * end of the string. |
584 */ | 597 */ |
585 char_u * | 598 char_u * |
586 vim_strchr(char_u *string, int c) | 599 vim_strchr(char_u *string, int c) |
587 { | 600 { |
588 char_u *p; | 601 char_u *p; |
589 int b; | 602 int b; |
590 | 603 |