fixups
Some checks failed
Release / Bump Homebrew formula (push) Has been cancelled

This commit is contained in:
2025-11-28 03:20:33 -08:00
parent 78e4f84f7b
commit 5d581c1c2f
2 changed files with 70 additions and 58 deletions

View File

@@ -4,7 +4,7 @@ project(ke C) # Specify C language explicitly
set(CMAKE_C_STANDARD 99)
set(KE_VERSION "2.0.1")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g")
set(CMAKE_C_FLAGS "-Wall -Wextra -pedantic -Wshadow -Werror -std=c99 -g -Werror=stringop-truncation")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D_DEFAULT_SOURCE -D_XOPEN_SOURCE")
# Optionally enable AddressSanitizer (ASan)

40
main.c
View File

@@ -298,8 +298,15 @@ file_open_prompt_cb(char *buf, const int16_t key)
strncat(newbuf, "/", sizeof(newbuf) - strlen(newbuf) - 1);
}
strncpy(buf, newbuf[0] ? newbuf : names[0], 127);
buf[127] = '\0';
/* copy to input buffer (max 127 chars + NUL) avoiding truncation warnings */
do {
const char *src__ = newbuf[0] ? newbuf : names[0];
size_t cap__ = 128u;
size_t len__ = strnlen(src__, cap__ - 1);
memcpy(buf, src__, len__);
buf[len__] = '\0';
} while (0);
editor_set_status("Unique match: %s%s", names[0], isdir[0] ? "/" : "");
} else {
cur = strlen(base);
@@ -318,8 +325,14 @@ file_open_prompt_cb(char *buf, const int16_t key)
strncat(newbuf, base, sizeof(newbuf) - strlen(newbuf) - 1);
}
strncpy(buf, newbuf, 127);
buf[127] = '\0';
/* copy to input buffer (max 127 chars + NUL) avoiding truncation warnings */
do {
const char *src__ = newbuf;
size_t cap__ = 128u;
size_t len__ = strnlen(src__, cap__ - 1);
memcpy(buf, src__, len__);
buf[len__] = '\0';
} while (0);
size_t used = 0;
used += snprintf(msg + used, sizeof(msg) - used, "%d matches: ", n);
@@ -842,18 +855,17 @@ delete_region(void)
void
jump_to_position(int col, int row)
{
/* Handle empty buffer safely */
if (ENROWS <= 0) {
ECURX = 0;
ECURY = 0;
/* Keep legacy globals in sync with per-buffer fields for rendering */
editor.curx = ECURX;
editor.cury = ECURY;
display_refresh();
return;
}
/* clamp position using per-buffer dimensions */
if (row < 0) {
row = 0;
} else if (row >= ENROWS) {
@@ -868,7 +880,7 @@ jump_to_position(int col, int row)
ECURX = col;
ECURY = row;
/* Keep legacy globals in sync with per-buffer fields for rendering */
editor.curx = ECURX;
editor.cury = ECURY;
@@ -1698,26 +1710,26 @@ editor_find(void)
void
editor_openfile(void)
{
char *filename;
char *filename = NULL;
buffer *cur = NULL;
int nb = NULL;
/* Add TAB completion for path input */
filename = editor_prompt("Load file: %s", file_open_prompt_cb);
if (filename == NULL) {
return;
}
/* If the only buffer is an unnamed, empty buffer, reuse it */
buffer *cur = buffer_current();
cur = buffer_current();
if (editor.bufcount == 1 && buffer_is_unnamed_and_empty(cur)) {
open_file(filename);
buffer_save_current();
} else {
/* Open into a new buffer */
int nb = buffer_add_empty();
nb = buffer_add_empty();
buffer_switch(nb);
open_file(filename);
buffer_save_current();
}
free(filename);
}