fixup: apply the change on more files

This commit is contained in:
James Tirta Halim
2024-06-03 11:10:30 +07:00
committed by Lewis Russell
parent 4b3845be2e
commit 200e7ad157
19 changed files with 45 additions and 45 deletions

View File

@ -1375,7 +1375,7 @@ static inline void init_line_array(lua_State *lstate, Array *a, size_t size, Are
/// @param s String to push
/// @param len Size of string
/// @param idx 0-based index to place s (only used for Lua)
/// @param replace_nl Replace newlines ('\n') with null ('\0')
/// @param replace_nl Replace newlines ('\n') with null (NUL)
static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len, int idx,
bool replace_nl, Arena *arena)
{
@ -1384,7 +1384,7 @@ static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len,
if (s && replace_nl && strchr(s, '\n')) {
// TODO(bfredl): could manage scratch space in the arena, for the NUL case
char *tmp = xmemdupz(s, len);
strchrsub(tmp, '\n', '\0');
strchrsub(tmp, '\n', NUL);
lua_pushlstring(lstate, tmp, len);
xfree(tmp);
} else {
@ -1397,7 +1397,7 @@ static void push_linestr(lua_State *lstate, Array *a, const char *s, size_t len,
str = CBUF_TO_ARENA_STR(arena, s, len);
if (replace_nl) {
// Vim represents NULs as NLs, but this may confuse clients.
strchrsub(str.data, '\n', '\0');
strchrsub(str.data, '\n', NUL);
}
}

View File

@ -193,7 +193,7 @@ Dict(cmd) nvim_parse_cmd(String str, Dict(empty) *opts, Arena *arena, Error *err
} else {
nargs[0] = '0';
}
nargs[1] = '\0';
nargs[1] = NUL;
PUT_KEY(result, cmd, nargs, CSTR_TO_ARENA_OBJ(arena, nargs));
char *addr;
@ -391,7 +391,7 @@ String nvim_cmd(uint64_t channel_id, Dict(cmd) *cmd, Dict(cmd_opts) *opts, Arena
case kObjectTypeBoolean:
data_str = arena_alloc(arena, 2, false);
data_str[0] = elem.data.boolean ? '1' : '0';
data_str[1] = '\0';
data_str[1] = NUL;
ADD_C(args, CSTR_AS_OBJ(data_str));
break;
case kObjectTypeBuffer:

View File

@ -17,7 +17,7 @@ void api_err_invalid(Error *err, const char *name, const char *val_s, int64_t va
char *has_space = strchr(name, ' ');
// No value.
if (val_s && val_s[0] == '\0') {
if (val_s && val_s[0] == NUL) {
api_set_error(err, errtype, has_space ? "Invalid %s" : "Invalid '%s'", name);
return;
}

View File

@ -109,7 +109,7 @@ String exec_impl(uint64_t channel_id, String src, Dict(exec_opts) *opts, Error *
// redir usually (except :echon) prepends a newline.
if (s.data[0] == '\n') {
memmove(s.data, s.data + 1, s.size - 1);
s.data[s.size - 1] = '\0';
s.data[s.size - 1] = NUL;
s.size = s.size - 1;
}
return s; // Caller will free the memory.

View File

@ -855,7 +855,7 @@ char *encode_tv2string(typval_T *tv, size_t *len)
if (len != NULL) {
*len = (size_t)ga.ga_len;
}
ga_append(&ga, '\0');
ga_append(&ga, NUL);
return (char *)ga.ga_data;
}
@ -883,7 +883,7 @@ char *encode_tv2echo(typval_T *tv, size_t *len)
if (len != NULL) {
*len = (size_t)ga.ga_len;
}
ga_append(&ga, '\0');
ga_append(&ga, NUL);
return (char *)ga.ga_data;
}
@ -908,7 +908,7 @@ char *encode_tv2json(typval_T *tv, size_t *len)
if (len != NULL) {
*len = (size_t)ga.ga_len;
}
ga_append(&ga, '\0');
ga_append(&ga, NUL);
return (char *)ga.ga_data;
}

View File

@ -4318,7 +4318,7 @@ static dict_T *create_environment(const dictitem_T *job_env, const bool clear_en
// Set $NVIM (in the child process) to v:servername. #3118
char *nvim_addr = get_vim_var_str(VV_SEND_SERVER);
if (nvim_addr[0] != '\0') {
if (nvim_addr[0] != NUL) {
dictitem_T *dv = tv_dict_find(env, S_LEN("NVIM"));
if (dv) {
tv_dict_item_remove(env, dv);
@ -9174,13 +9174,13 @@ static void f_termopen(typval_T *argvars, typval_T *rettv, EvalFuncData fptr)
size_t len = home_replace(NULL, NameBuff, IObuff, sizeof(IObuff), true);
// Trim slash.
if (len != 1 && (IObuff[len - 1] == '\\' || IObuff[len - 1] == '/')) {
IObuff[len - 1] = '\0';
IObuff[len - 1] = NUL;
}
if (len == 1 && IObuff[0] == '/') {
// Avoid ambiguity in the URI when CWD is root directory.
IObuff[1] = '.';
IObuff[2] = '\0';
IObuff[2] = NUL;
}
// Terminal URI: "term://$CWD//$PID:$CMD"

View File

@ -1824,7 +1824,7 @@ char *callback_to_string(Callback *cb, Arena *arena)
snprintf(msg, msglen, "<vim partial: %s>", cb->data.partial->pt_name);
break;
default:
*msg = '\0';
*msg = NUL;
break;
}
return msg;

View File

@ -272,7 +272,7 @@ static int get_winnr(tabpage_T *tp, typval_T *argvar)
// if count is not specified, default to 1
count = 1;
}
if (endp != NULL && *endp != '\0') {
if (endp != NULL && *endp != NUL) {
if (strequal(endp, "j")) {
twin = win_vert_neighbor(tp, twin, false, count);
} else if (strequal(endp, "k")) {

View File

@ -35,7 +35,7 @@ int socket_watcher_init(Loop *loop, SocketWatcher *watcher, const char *endpoint
if (host_end && addr != host_end) {
// Split user specified address into two strings, addr(hostname) and port.
// The port part in watcher->addr will be updated later.
*host_end = '\0';
*host_end = NUL;
char *port = host_end + 1;
intmax_t iport;

View File

@ -104,12 +104,12 @@ void ex_trust(exarg_T *eap)
action = "deny";
} else if (strcmp(arg1, "++remove") == 0) {
action = "remove";
} else if (*arg1 != '\0') {
} else if (*arg1 != NUL) {
semsg(e_invarg2, arg1);
goto theend;
}
if (path[0] == '\0') {
if (path[0] == NUL) {
path = NULL;
}

View File

@ -279,7 +279,7 @@ static const char *input_cb(void *payload, uint32_t byte_index, TSPoint position
memcpy(buf, line + position.column, tocopy);
// Translate embedded \n to NUL
memchrsub(buf, '\n', '\0', tocopy);
memchrsub(buf, '\n', NUL, tocopy);
*bytes_read = (uint32_t)tocopy;
if (tocopy < BUFSIZE) {
// now add the final \n. If it didn't fit, input_cb will be called again

View File

@ -131,7 +131,7 @@ bool server_owns_pipe_address(const char *path)
/// @returns 0: success, 1: validation error, 2: already listening, -errno: failed to bind/listen.
int server_start(const char *addr)
{
if (addr == NULL || addr[0] == '\0') {
if (addr == NULL || addr[0] == NUL) {
WLOG("Empty or NULL address");
return 1;
}

View File

@ -63,13 +63,13 @@ const char *os_getenv(const char *name)
FUNC_ATTR_NONNULL_ALL
{
char *e = NULL;
if (name[0] == '\0') {
if (name[0] == NUL) {
return NULL;
}
int r = 0;
if (map_has(cstr_t, &envmap, name)
&& !!(e = (char *)pmap_get(cstr_t)(&envmap, name))) {
if (e[0] != '\0') {
if (e[0] != NUL) {
// Found non-empty cached env var.
// NOTE: This risks incoherence if an in-process library changes the
// environment without going through our os_setenv() wrapper. If
@ -85,11 +85,11 @@ const char *os_getenv(const char *name)
if (r == UV_ENOBUFS) {
e = xmalloc(size);
r = uv_os_getenv(name, e, &size);
if (r != 0 || size == 0 || e[0] == '\0') {
if (r != 0 || size == 0 || e[0] == NUL) {
XFREE_CLEAR(e);
goto end;
}
} else if (r != 0 || size == 0 || buf[0] == '\0') {
} else if (r != 0 || size == 0 || buf[0] == NUL) {
e = NULL;
goto end;
} else {
@ -110,7 +110,7 @@ end:
bool os_env_exists(const char *name)
FUNC_ATTR_NONNULL_ALL
{
if (name[0] == '\0') {
if (name[0] == NUL) {
return false;
}
// Use a tiny buffer because we don't care about the value: if uv_os_getenv()
@ -134,14 +134,14 @@ bool os_env_exists(const char *name)
int os_setenv(const char *name, const char *value, int overwrite)
FUNC_ATTR_NONNULL_ALL
{
if (name[0] == '\0') {
if (name[0] == NUL) {
return -1;
}
#ifdef MSWIN
if (!overwrite && os_getenv(name) != NULL) {
return 0;
}
if (value[0] == '\0') {
if (value[0] == NUL) {
// Windows (Vim-compat): Empty string undefines the env var.
return os_unsetenv(name);
}
@ -174,7 +174,7 @@ int os_setenv(const char *name, const char *value, int overwrite)
int os_unsetenv(const char *name)
FUNC_ATTR_NONNULL_ALL
{
if (name[0] == '\0') {
if (name[0] == NUL) {
return -1;
}
pmap_del2(&envmap, name);
@ -366,7 +366,7 @@ void os_get_hostname(char *hostname, size_t size)
struct utsname vutsname;
if (uname(&vutsname) < 0) {
*hostname = '\0';
*hostname = NUL;
} else {
xstrlcpy(hostname, vutsname.nodename, size);
}
@ -374,12 +374,12 @@ void os_get_hostname(char *hostname, size_t size)
wchar_t host_utf16[MAX_COMPUTERNAME_LENGTH + 1];
DWORD host_wsize = sizeof(host_utf16) / sizeof(host_utf16[0]);
if (GetComputerNameW(host_utf16, &host_wsize) == 0) {
*hostname = '\0';
*hostname = NUL;
DWORD err = GetLastError();
semsg("GetComputerNameW failed: %d", err);
return;
}
host_utf16[host_wsize] = '\0';
host_utf16[host_wsize] = NUL;
char *host_utf8;
int conversion_result = utf16_to_utf8(host_utf16, -1, &host_utf8);
@ -391,7 +391,7 @@ void os_get_hostname(char *hostname, size_t size)
xfree(host_utf8);
#else
emsg("os_get_hostname failed: missing uname()");
*hostname = '\0';
*hostname = NUL;
#endif
}
@ -885,9 +885,9 @@ void vim_get_prefix_from_exepath(char *exe_name)
// but c_grammar.lua does not recognize it (yet).
xstrlcpy(exe_name, get_vim_var_str(VV_PROGPATH), MAXPATHL * sizeof(*exe_name));
char *path_end = path_tail_with_sep(exe_name);
*path_end = '\0'; // remove the trailing "nvim.exe"
*path_end = NUL; // remove the trailing "nvim.exe"
path_end = path_tail(exe_name);
*path_end = '\0'; // remove the trailing "bin/"
*path_end = NUL; // remove the trailing "bin/"
}
/// Vim getenv() wrapper with special handling of $HOME, $VIM, $VIMRUNTIME,

View File

@ -302,7 +302,7 @@ static bool is_executable_ext(const char *name, char **abspath)
char *nameext = strrchr(name, '.');
size_t nameext_len = nameext ? strlen(nameext) : 0;
xstrlcpy(os_buf, name, sizeof(os_buf));
char *buf_end = xstrchrnul(os_buf, '\0');
char *buf_end = xstrchrnul(os_buf, NUL);
const char *pathext = os_getenv("PATHEXT");
if (!pathext) {
pathext = ".com;.exe;.bat;.cmd";
@ -310,7 +310,7 @@ static bool is_executable_ext(const char *name, char **abspath)
const char *ext = pathext;
while (*ext) {
// If $PATHEXT itself contains dot:
if (ext[0] == '.' && (ext[1] == '\0' || ext[1] == ENV_SEPCHAR)) {
if (ext[0] == '.' && (ext[1] == NUL || ext[1] == ENV_SEPCHAR)) {
if (is_executable(name, abspath)) {
return true;
}
@ -436,7 +436,7 @@ FILE *os_fopen(const char *path, const char *flags)
assert(flags != NULL && strlen(flags) > 0 && strlen(flags) <= 2);
int iflags = 0;
// Per table in fopen(3) manpage.
if (flags[1] == '\0' || flags[1] == 'b') {
if (flags[1] == NUL || flags[1] == 'b') {
switch (flags[0]) {
case 'r':
iflags = O_RDONLY;

View File

@ -399,7 +399,7 @@ static int build_env_block(dict_T *denv, wchar_t **env_block)
QUEUE_INSERT_TAIL(&env_q, &env_node->node);
}
// Additional '\0' after the final entry
// Additional NUL after the final entry
env_block_len++;
*env_block = xmalloc(sizeof(**env_block) * env_block_len);

View File

@ -648,13 +648,13 @@ char *shell_argv_to_str(char **const argv)
p++;
}
if (n < maxsize) {
rv[n - 1] = '\0';
rv[n - 1] = NUL;
} else {
// Command too long, show ellipsis: "/bin/bash 'foo' 'bar'..."
rv[maxsize - 4] = '.';
rv[maxsize - 3] = '.';
rv[maxsize - 2] = '.';
rv[maxsize - 1] = '\0';
rv[maxsize - 1] = NUL;
}
return rv;
}
@ -861,7 +861,7 @@ static int do_os_system(char **argv, const char *input, size_t len, char **outpu
{
out_data_decide_throttle(0); // Initialize throttle decider.
out_data_ring(NULL, 0); // Initialize output ring-buffer.
bool has_input = (input != NULL && input[0] != '\0');
bool has_input = (input != NULL && input[0] != NUL);
// the output buffer
DynamicBuffer buf = DYNAMIC_BUFFER_INIT;
@ -1024,7 +1024,7 @@ static bool out_data_decide_throttle(size_t size)
static uint64_t started = 0; // Start time of the current throttle.
static size_t received = 0; // Bytes observed since last throttle.
static size_t visit = 0; // "Pulse" count of the current throttle.
static char pulse_msg[] = { ' ', ' ', ' ', '\0' };
static char pulse_msg[] = { ' ', ' ', ' ', NUL };
if (!size) {
bool previous_decision = (visit > 0);

View File

@ -69,7 +69,7 @@ static const char *const xdg_defaults[] = {
const char *get_appname(void)
{
const char *env_val = os_getenv("NVIM_APPNAME");
if (env_val == NULL || *env_val == '\0') {
if (env_val == NULL || *env_val == NUL) {
env_val = "nvim";
}
return env_val;

View File

@ -35,7 +35,7 @@ bool terminfo_is_term_family(const char *term, const char *family)
// The screen terminfo may have a terminal name like screen.xterm. By making
// the dot(.) a valid separator, such terminal names will also be the
// terminal family of the screen.
&& ('\0' == term[flen] || '-' == term[flen] || '.' == term[flen]);
&& (NUL == term[flen] || '-' == term[flen] || '.' == term[flen]);
}
bool terminfo_is_bsd_console(const char *term)

View File

@ -2508,7 +2508,7 @@ static const char *tui_get_stty_erase(int fd)
struct termios t;
if (tcgetattr(fd, &t) != -1) {
stty_erase[0] = (char)t.c_cc[VERASE];
stty_erase[1] = '\0';
stty_erase[1] = NUL;
DLOG("stty/termios:erase=%s", stty_erase);
}
#endif