aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mbyte.c
diff options
context:
space:
mode:
authorLewis Russell <lewis6991@gmail.com>2023-08-13 10:29:43 +0100
committerLewis Russell <me@lewisr.dev>2023-08-31 15:12:35 +0100
commita1bec02c1e105eb9f49d577e04bdbeadd5a05e38 (patch)
tree894faacc22be90a78ba9c7d4ae9072782d465439 /src/nvim/mbyte.c
parentdd0e77d48a843fc9730fe4ef7567330daf8dfb81 (diff)
downloadrneovim-a1bec02c1e105eb9f49d577e04bdbeadd5a05e38.tar.gz
rneovim-a1bec02c1e105eb9f49d577e04bdbeadd5a05e38.tar.bz2
rneovim-a1bec02c1e105eb9f49d577e04bdbeadd5a05e38.zip
fix: use snprintf instead of sprintf
Clang 14 now reports sprintf as deprecated.
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r--src/nvim/mbyte.c19
1 files changed, 8 insertions, 11 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 92e70350bb..fd9efb1387 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -1522,21 +1522,17 @@ int mb_stricmp(const char *s1, const char *s2)
// 'encoding' has been set to.
void show_utf8(void)
{
- int len;
- int rlen = 0;
- char *line;
- int clen;
-
// Get the byte length of the char under the cursor, including composing
// characters.
- line = get_cursor_pos_ptr();
- len = utfc_ptr2len(line);
+ char *line = get_cursor_pos_ptr();
+ int len = utfc_ptr2len(line);
if (len == 0) {
msg("NUL");
return;
}
- clen = 0;
+ size_t rlen = 0;
+ int clen = 0;
for (int i = 0; i < len; i++) {
if (clen == 0) {
// start of (composing) character, get its length
@@ -1546,10 +1542,11 @@ void show_utf8(void)
}
clen = utf_ptr2len(line + i);
}
- sprintf(IObuff + rlen, "%02x ", // NOLINT(runtime/printf)
- (line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
+ assert(IOSIZE > rlen);
+ snprintf(IObuff + rlen, IOSIZE - rlen, "%02x ",
+ (line[i] == NL) ? NUL : (uint8_t)line[i]); // NUL is stored as NL
clen--;
- rlen += (int)strlen(IObuff + rlen);
+ rlen += strlen(IObuff + rlen);
if (rlen > IOSIZE - 20) {
break;
}