Replace '\0' to NUL to make it more clear that it is a NUL-terminated string.

This commit is contained in:
René van Dorst
2026-08-25 07:55:06 +02:00
parent 5d42e8843e
commit 2ff418f80f
5 changed files with 35 additions and 34 deletions
+1 -1
View File
@@ -193,7 +193,7 @@ void cmd_edit(void) __banked
// Check whether return was pressed: // Check whether return was pressed:
if (sbuf[l] == '\n' || sbuf[l] == '\r') { if (sbuf[l] == '\n' || sbuf[l] == '\r') {
write_char('\n'); write_char('\n');
cmd_buffer[cmd_line_len] = '\0'; cmd_buffer[cmd_line_len] = NUL;
// write_char('>'); print_string_x(cmd_buffer); write_char('<'); // write_char('>'); print_string_x(cmd_buffer); write_char('<');
// If there is a command we print the prompt after execution // If there is a command we print the prompt after execution
// otherwise immediately because there is nothing to execute // otherwise immediately because there is nothing to execute
+19 -19
View File
@@ -114,8 +114,8 @@ uint8_t cmd_compare(uint8_t start, __code uint8_t * cmd)
uint8_t b = cmd_buffer[i]; uint8_t b = cmd_buffer[i];
// cmd is garanteerd to be NULL-terminated. // cmd is garanteerd to be NULL-terminated.
if (c == '\0') { if (c == NUL) {
if ((b == ' ') || (b == '\0')) { if ((b == ' ') || (b == NUL)) {
// Match // Match
return 1; return 1;
} }
@@ -147,7 +147,7 @@ uint8_t atoi_hex(uint8_t idx)
while(1) { while(1) {
c = cmd_buffer[idx]; c = cmd_buffer[idx];
if (c == '\0' || c == ' ') { if (c == NUL || c == ' ') {
break; break;
} }
@@ -263,7 +263,7 @@ uint8_t cmd_parse_port_separator(uint8_t idx) {
uint8_t c = cmd_buffer[idx]; uint8_t c = cmd_buffer[idx];
if (c == ' ') { if (c == ' ') {
ret++; ret++;
} else if (c != '\0') } else if (c != NUL)
ret = 0; ret = 0;
} }
return ret; return ret;
@@ -278,7 +278,7 @@ __bit cmd_is_space(uint8_t idx) {
// check if the cmd_buffer[idx] is a space or NULL. // check if the cmd_buffer[idx] is a space or NULL.
__bit cmd_is_space_or_nul(uint8_t idx) { __bit cmd_is_space_or_nul(uint8_t idx) {
uint8_t c = cmd_buffer[idx]; uint8_t c = cmd_buffer[idx];
return c == ' ' || c == '\0'; return c == ' ' || c == NUL;
} }
// returns 0 when on parser error or invalid value or no space. // returns 0 when on parser error or invalid value or no space.
@@ -304,7 +304,7 @@ uint8_t parse_ip(uint8_t idx)
idx++; idx++;
break; break;
} }
if (ret == '\0') if (ret == NUL)
break; break;
goto err; goto err;
} }
@@ -483,7 +483,7 @@ void parse_vlan(void)
write_char(cmd_buffer[cmd_words_b[w] + i]); write_char(cmd_buffer[cmd_words_b[w] + i]);
vlan_names[vlan_ptr++] = cmd_buffer[cmd_words_b[w] + i++]; vlan_names[vlan_ptr++] = cmd_buffer[cmd_words_b[w] + i++];
} }
vlan_names[vlan_ptr++] = ' '; vlan_names[vlan_ptr] = '\0'; vlan_names[vlan_ptr++] = ' '; vlan_names[vlan_ptr] = NUL;
w++; w++;
print_string("<\n"); print_string("<\n");
} }
@@ -738,11 +738,11 @@ void parse_port(void)
} }
} else if (cmd_compare(2, "name")) { } else if (cmd_compare(2, "name")) {
uint8_t i = 0; uint8_t i = 0;
while ( (i < PORT_NAME_SIZE-1) && (cmd_buffer[cmd_words_b[3] + i] != '\0') ) { while ( (i < PORT_NAME_SIZE-1) && (cmd_buffer[cmd_words_b[3] + i] != NUL) ) {
port_names[phy_settings.port][i] = cmd_buffer[cmd_words_b[3] + i]; port_names[phy_settings.port][i] = cmd_buffer[cmd_words_b[3] + i];
i++; i++;
} }
port_names[phy_settings.port][i] = '\0'; port_names[phy_settings.port][i] = NUL;
print_string("\nName set to: \""); print_string("\nName set to: \"");
print_string_x(port_names[phy_settings.port]); print_string_x(port_names[phy_settings.port]);
print_string("\"\n"); print_string("\"\n");
@@ -1248,8 +1248,8 @@ void parse_passwd(void)
do { do {
c = cmd_buffer[i++]; c = cmd_buffer[i++];
passwd[j++] = c; passwd[j++] = c;
} while (c != '\0' && j < 20); } while (c != NUL && j < 20);
passwd[j] = '\0'; passwd[j] = NUL;
return; return;
} }
print_string("Missing password\n"); print_string("Missing password\n");
@@ -1453,7 +1453,7 @@ void cmd_tokenize(void) __banked
while(1) { while(1) {
c = cmd_buffer[line_ptr]; c = cmd_buffer[line_ptr];
if (c == '\0') { if (c == NUL) {
// Store the word count // Store the word count
cmd_words_len = word; cmd_words_len = word;
break; break;
@@ -1658,13 +1658,13 @@ void cmd_parser(void) __banked
__xdata char *dst = hostname; __xdata char *dst = hostname;
for (uint8_t hn = 0; hn < sizeof(hostname) - 1; hn++) { for (uint8_t hn = 0; hn < sizeof(hostname) - 1; hn++) {
uint8_t c = *hp++; uint8_t c = *hp++;
if (c == '\0' || c == '\r' || c == '\n') if (c == NUL || c == '\r' || c == '\n')
break; break;
if (c < 0x20 || c > 0x7e || c == '"' || c == '\\') if (c < 0x20 || c > 0x7e || c == '"' || c == '\\')
c = '.'; c = '.';
*dst++ = c; *dst++ = c;
} }
*dst = '\0'; *dst = NUL;
} else { } else {
print_string("Error: hostname [name] - the name must not contain spaces\n"); print_string("Error: hostname [name] - the name must not contain spaces\n");
} }
@@ -1752,7 +1752,7 @@ void cmd_parser(void) __banked
uint8_t i = cmd_words_b[cmd_words_len - 1]; uint8_t i = cmd_words_b[cmd_words_len - 1];
do { do {
i++; i++;
} while(cmd_buffer[i] != '\0'); } while(cmd_buffer[i] != NUL);
// Copy last cmd-buffer to history. // Copy last cmd-buffer to history.
cmd_history_ptr = (cmd_history_ptr + i) & CMD_HISTORY_MASK; cmd_history_ptr = (cmd_history_ptr + i) & CMD_HISTORY_MASK;
@@ -1800,7 +1800,7 @@ void execute_config(void) __banked
uint8_t c = 0; uint8_t c = 0;
do { do {
if (cmd_idx >= (CMD_BUF_SIZE - 1)) { if (cmd_idx >= (CMD_BUF_SIZE - 1)) {
cmd_buffer[cmd_idx] = '\0'; cmd_buffer[cmd_idx] = NUL;
print_string("ERROR: Command too long: "); print_string("ERROR: Command too long: ");
print_string_x(cmd_buffer); print_string_x(cmd_buffer);
write_char('\n'); write_char('\n');
@@ -1809,7 +1809,7 @@ void execute_config(void) __banked
} }
c = flash_buf[cfg_idx++]; c = flash_buf[cfg_idx++];
if (c == 0 || c == '\n') { if (c == 0 || c == '\n') {
cmd_buffer[cmd_idx] = '\0'; cmd_buffer[cmd_idx] = NUL;
if (cmd_idx) { if (cmd_idx) {
cmd_tokenize(); cmd_tokenize();
if (err_status != ERR_OK) if (err_status != ERR_OK)
@@ -1845,7 +1845,7 @@ void execute_commands(__xdata uint8_t *p) __banked {
while (1) { while (1) {
if (*p == 0 || *p == '\n' || *p == '\r') { if (*p == 0 || *p == '\n' || *p == '\r') {
if (cmd_idx) { if (cmd_idx) {
cmd_buffer[cmd_idx] = '\0'; cmd_buffer[cmd_idx] = NUL;
cmd_tokenize(); cmd_tokenize();
if (err_status != ERR_OK) if (err_status != ERR_OK)
return; return;
@@ -1858,7 +1858,7 @@ void execute_commands(__xdata uint8_t *p) __banked {
if (cmd_idx < (CMD_BUF_SIZE - 1)) { if (cmd_idx < (CMD_BUF_SIZE - 1)) {
cmd_buffer[cmd_idx++] = *p; cmd_buffer[cmd_idx++] = *p;
} else { } else {
cmd_buffer[CMD_BUF_SIZE - 1] = '\0'; cmd_buffer[CMD_BUF_SIZE - 1] = NUL;
print_string("ERROR: Command too long: "); print_string("ERROR: Command too long: ");
print_string_x(cmd_buffer); print_string_x(cmd_buffer);
write_char('\n'); write_char('\n');
+10 -10
View File
@@ -119,8 +119,8 @@ bool is_word(__xdata uint8_t *xdata_str_p, __code uint8_t * __xdata code_str_p)
u = *xdata_str_p++; u = *xdata_str_p++;
c = *code_str_p++; c = *code_str_p++;
if (c == '\0') { if (c == NUL) {
if (u != '\0' && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r') if (u != NUL && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r')
return false; return false;
return true; return true;
} }
@@ -140,8 +140,8 @@ bool is_url_word_x(__xdata uint8_t *uri_str_p, __xdata uint8_t *src_str_p)
u = *uri_str_p++; u = *uri_str_p++;
s = *src_str_p++; s = *src_str_p++;
if (s == '\0') { if (s == NUL) {
if (u != '\0' && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r') if (u != NUL && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r')
return false; return false;
return true; return true;
} }
@@ -183,9 +183,9 @@ bool is_word_x(__xdata uint8_t *lhs_str_p, __xdata uint8_t *rhs_str_p)
u = *lhs_str_p++; u = *lhs_str_p++;
c = *rhs_str_p++; c = *rhs_str_p++;
if (c == '\0') { if (c == NUL) {
/* ';' separates cookies in a Cookie header, so it ends a value too. */ /* ';' separates cookies in a Cookie header, so it ends a value too. */
if (u != '\0' && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r' && u != ';') if (u != NUL && u != ' ' && u != '\t' && u != ':' && u != '?' && u != '=' && u != '\n' && u != '\r' && u != ';')
return false; return false;
return true; return true;
} }
@@ -487,10 +487,10 @@ void handle_post(void)
// Find end of request path // Find end of request path
while (*p && !is_separator(*p)) while (*p && !is_separator(*p))
p++; p++;
*p++ = '\0'; *p++ = NUL;
// Find end of request header // Find end of request header
boundary[0] ='\0'; boundary[0] =NUL;
p = scan_header(p); p = scan_header(p);
dbg_string("Boundary: >"); dbg_string_x(boundary); dbg_string("<\n"); dbg_string("Boundary: >"); dbg_string_x(boundary); dbg_string("<\n");
if (!*p || !content_type) { if (!*p || !content_type) {
@@ -550,7 +550,7 @@ void handle_post(void)
dbg_string("Password accepted!\n"); dbg_string("Password accepted!\n");
read_reg_timer(&last_session_use); read_reg_timer(&last_session_use);
gen_random_bytes(session_id, SESSION_ID_LENGTH); gen_random_bytes(session_id, SESSION_ID_LENGTH);
session_id[SESSION_ID_LENGTH] = '\0'; session_id[SESSION_ID_LENGTH] = NUL;
slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nConnection: close\r\nLocation: index.html\r\n" \ slen = strtox(outbuf, "HTTP/1.1 302 Found\r\nConnection: close\r\nLocation: index.html\r\n" \
"Set-Cookie: session="); "Set-Cookie: session=");
for (register uint8_t i = 0; i < SESSION_ID_LENGTH; i++) for (register uint8_t i = 0; i < SESSION_ID_LENGTH; i++)
@@ -736,7 +736,7 @@ void httpd_appcall(void)
__xdata uint8_t *q = p; __xdata uint8_t *q = p;
while (*p && !is_separator(*p)) while (*p && !is_separator(*p))
p++; p++;
*p = '\0'; *p = NUL;
dbg_string_x(q); dbg_string_x(q);
dbg_char('\n'); dbg_char('\n');
+1
View File
@@ -8,6 +8,7 @@
#define SYS_TICK_HZ 200 #define SYS_TICK_HZ 200
#define CPU_PORT 9 #define CPU_PORT 9
#define NUL '\0'
// Define Port-masks for 9-port devices and 6-port devices // Define Port-masks for 9-port devices and 6-port devices
#define PMASK_9 0x1ff #define PMASK_9 0x1ff
+4 -4
View File
@@ -1257,11 +1257,11 @@ bool sfp_read_field(__xdata char *dst, uint8_t sfp, uint8_t start, uint8_t lengt
if (!sfp_read_block(sfp, start, length)) if (!sfp_read_block(sfp, start, length))
return false; return false;
dst[length] = '\0'; dst[length] = NUL;
memcpy(dst, sfp_buf, length); memcpy(dst, sfp_buf, length);
while (length > 0 && dst[--length] == ' ') while (length > 0 && dst[--length] == ' ')
dst[length] = '\0'; dst[length] = NUL;
return true; return true;
} }
@@ -2069,7 +2069,7 @@ void check_and_flash_update_image(void)
* because itohex() is inline and brings its own frame. */ * because itohex() is inline and brings its own frame. */
void set_hostname_default(void) void set_hostname_default(void)
{ {
if (hostname[0] != '\0') if (hostname[0] != NUL)
return; return;
strcpy((__xdata uint8_t *)hostname, "RTLPlayground-"); strcpy((__xdata uint8_t *)hostname, "RTLPlayground-");
@@ -2079,7 +2079,7 @@ void set_hostname_default(void)
hostname[17] = hex[uip_ethaddr.addr[4] & 0xf]; hostname[17] = hex[uip_ethaddr.addr[4] & 0xf];
hostname[18] = hex[uip_ethaddr.addr[5] >> 4]; hostname[18] = hex[uip_ethaddr.addr[5] >> 4];
hostname[19] = hex[uip_ethaddr.addr[5] & 0xf]; hostname[19] = hex[uip_ethaddr.addr[5] & 0xf];
hostname[20] = '\0'; hostname[20] = NUL;
} }