Fix minor issues in user apps

Uninitialized variables, reading past array end, etc.
This commit is contained in:
2026-08-25 21:41:25 +03:00
parent d72169473f
commit b78ef69da8
4 changed files with 10 additions and 6 deletions
+1 -1
View File
@@ -5,7 +5,7 @@
#define BLOCK_SIZE 65536 #define BLOCK_SIZE 65536
exit_code_t pass(uint64_t fd) { exit_code_t pass(uint64_t fd) {
static char buffer[BLOCK_SIZE]; char buffer[BLOCK_SIZE];
uint64_t bytes; uint64_t bytes;
while ((bytes = read(fd, BLOCK_SIZE, buffer))) { while ((bytes = read(fd, BLOCK_SIZE, buffer))) {
if (bytes == (uint64_t)-1) { if (bytes == (uint64_t)-1) {
+1 -2
View File
@@ -10,8 +10,7 @@ exit_code_t main(uint64_t argc, const char **argv) {
uint64_t code = EXIT_CODE_OK; uint64_t code = EXIT_CODE_OK;
for (uint64_t i = 1; i < argc; i++) { for (uint64_t i = 1; i < argc; i++) {
uint64_t removed = remove(argv[i]); if (remove(argv[i]) == (uint64_t)-1) {
if (removed == (uint64_t)-1) {
ERR_S("rm: could not remove file\n"); ERR_S("rm: could not remove file\n");
code = EXIT_CODE_GENERAL_FAILURE; code = EXIT_CODE_GENERAL_FAILURE;
} }
+7 -2
View File
@@ -96,7 +96,12 @@ static void execute(char *command) {
uint8_t pids_count = 0; uint8_t pids_count = 0;
for (uint8_t i = 0; i < subcommands_count; i++) { for (uint8_t i = 0; i < subcommands_count; i++) {
string_trim(subcommands[i], ' ', &subcommands[i]); if (!string_trim(subcommands[i], ' ', &subcommands[i])) {
if (subcommands_count > 1) {
ERR_S("Syntax error.\n");
}
break;
}
char *argv[16]; char *argv[16];
uint8_t argc = (uint8_t)string_split(subcommands[i], ' ', 16, argv); uint8_t argc = (uint8_t)string_split(subcommands[i], ' ', 16, argv);
@@ -166,7 +171,7 @@ exit_code_t main() {
print_prompt(); print_prompt();
char line[256]; char line[256];
uint64_t offset; uint64_t offset = 0;
char chunk[64]; char chunk[64];
uint64_t received; uint64_t received;
+1 -1
View File
@@ -6,7 +6,7 @@
#define BLOCK_SIZE 65536 #define BLOCK_SIZE 65536
exit_code_t pass(uint64_t fd) { exit_code_t pass(uint64_t fd) {
static char buffer[BLOCK_SIZE]; char buffer[BLOCK_SIZE];
uint64_t bytes; uint64_t bytes;
uint64_t total = 0; uint64_t total = 0;
while ((bytes = read(fd, BLOCK_SIZE, buffer))) { while ((bytes = read(fd, BLOCK_SIZE, buffer))) {