CE fix strange characters appearing at the end of file
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m46s

This commit is contained in:
2026-03-05 21:52:36 +01:00
parent abc7ac39c1
commit d7dc141874
6 changed files with 41 additions and 21 deletions

View File

@@ -4,6 +4,7 @@
#include <printf.h> #include <printf.h>
#include <stdarg.h> #include <stdarg.h>
#include <stddef.h> #include <stddef.h>
#include <string.h>
void cprintf (struct context* context, const char* fmt, ...) { void cprintf (struct context* context, const char* fmt, ...) {
va_list args; va_list args;
@@ -16,6 +17,7 @@ void cprintf (struct context* context, const char* fmt, ...) {
return; return;
} }
memset (buf, 0, CPRINTF_BUF_MAX);
int len = vsnprintf (buf, CPRINTF_BUF_MAX, fmt, args); int len = vsnprintf (buf, CPRINTF_BUF_MAX, fmt, args);
va_end (args); va_end (args);

View File

@@ -138,7 +138,7 @@ void edit_start (const char* file_path, const char* text) {
bb_remaining -= w; bb_remaining -= w;
} }
w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR2LEND "\n"); w = snprintf (bbptr, bb_remaining, ANSIQ_SCR_CLR2END "\n");
bbptr += w; bbptr += w;
bb_remaining -= w; bb_remaining -= w;

View File

@@ -2,6 +2,7 @@
#include "arena_alloc.h" #include "arena_alloc.h"
#include "context.h" #include "context.h"
#include "edit.h" #include "edit.h"
#include "mprintf.h"
#include "parser.h" #include "parser.h"
#include "self.h" #include "self.h"
#include <desc.h> #include <desc.h>

View File

@@ -3,6 +3,7 @@
#include <liballoc.h> #include <liballoc.h>
#include <printf.h> #include <printf.h>
#include <stdarg.h> #include <stdarg.h>
#include <string.h>
#include <system.h> #include <system.h>
void putchar_ (char ch) { (void)ch; } void putchar_ (char ch) { (void)ch; }
@@ -18,6 +19,7 @@ void mprintf (const char* fmt, ...) {
return; return;
} }
memset (buf, 0, MPRINTF_BUF_MAX);
int len = vsnprintf (buf, MPRINTF_BUF_MAX, fmt, args); int len = vsnprintf (buf, MPRINTF_BUF_MAX, fmt, args);
va_end (args); va_end (args);

View File

@@ -25,31 +25,39 @@ static struct tar_file* tar_get_file (struct tarfs* tarfs, const char* filename)
static size_t tar_get_size (uint8_t* in) { static size_t tar_get_size (uint8_t* in) {
size_t size = 0; size_t size = 0;
size_t j; for (size_t i = 0; i < 11; i++) {
size_t count = 1; if (in[i] < '0' || in[i] > '7')
break;
for (j = 11; j > 0; j--, count *= 8) size = (size * 8) + (in[i] - '0');
size += ((in[j - 1] - '0') * count); }
return size; return size;
} }
static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr) { static size_t tar_parse (struct tarfs* tarfs, uint8_t* addr, size_t max_size) {
size_t i; size_t i;
uint8_t* ptr = addr;
for (i = 0; i < TARFS_FILES_MAX; i++) { for (i = 0; i < TARFS_FILES_MAX; i++) {
struct tar_header* hdr = (struct tar_header*)addr; struct tar_header* hdr = (struct tar_header*)ptr;
if (hdr->filename[0] == '\0') if (hdr->filename[0] == '\0')
break; break;
if ((size_t)(ptr - addr) + 512 > max_size)
break;
size_t size = tar_get_size (hdr->size); size_t size = tar_get_size (hdr->size);
tarfs->tarfs_files[i].header = hdr; tarfs->tarfs_files[i].header = hdr;
tarfs->tarfs_files[i].content = (uint8_t*)((uintptr_t)hdr + 512); tarfs->tarfs_files[i].content = ptr + 512;
tarfs->tarfs_files[i].size = tar_get_size ((uint8_t*)hdr->size); tarfs->tarfs_files[i].size = size;
addr += 512 + ((size + 511) & ~511); ptr += 512 + ((size + 511) & ~511);
if ((size_t)(ptr - addr) > max_size)
break;
} }
return i; return i;
@@ -92,6 +100,7 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
if (buffer == NULL) { if (buffer == NULL) {
spin_unlock (&back_device->lock); spin_unlock (&back_device->lock);
free (volume->udata); free (volume->udata);
volume->udata = NULL;
return ret; return ret;
} }
@@ -105,12 +114,14 @@ int tarfs_mount (struct vfs_volume* volume, bool format) {
if (ret < 0) { if (ret < 0) {
free (buffer); free (buffer);
free (volume->udata);
volume->udata = NULL;
return ret; return ret;
} }
tarfs->buffer = buffer; tarfs->buffer = buffer;
tar_parse (tarfs, tarfs->buffer); tar_parse (tarfs, tarfs->buffer, total_size);
return ret; return ret;
} }
@@ -166,6 +177,9 @@ int tarfs_read_file (struct vfs_volume* volume, const char* path, uint8_t* buffe
if (file == NULL) if (file == NULL)
return -ST_NOT_FOUND; return -ST_NOT_FOUND;
if (off >= file->size)
return -ST_OOB_ERROR;
memcpy (buffer, (void*)((uintptr_t)file->content + off), min (size, file->size)); memcpy (buffer, (void*)((uintptr_t)file->content + off), min (size, file->size));
return ST_OK; return ST_OK;
@@ -183,19 +197,21 @@ int tarfs_read_dir_entry (struct vfs_volume* volume, const char* path, struct di
size_t entry_counter = 0; size_t entry_counter = 0;
for (size_t i = 0; i < TARFS_FILES_MAX; i++) { for (size_t i = 0; i < TARFS_FILES_MAX; i++) {
if ((tarfs->tarfs_files[i].header != NULL) && (entry_num == entry_counter)) { if (tarfs->tarfs_files[i].header != NULL) {
tar_file = &tarfs->tarfs_files[i]; if (entry_num == entry_counter) {
break; tar_file = &tarfs->tarfs_files[i];
break;
}
entry_counter++;
} }
entry_counter++;
} }
if (tar_file != NULL) { if (tar_file != NULL) {
sprintf (entry->path, "/%s", tar_file->header->filename); sprintf (entry->path, "/%s", tar_file->header->filename);
return ST_NOT_DIR; return ST_OK;
} }
return ST_DIR_NO_ENTRIES; return -ST_DIR_NO_ENTRIES;
} }
int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off, int tarfs_write_file (struct vfs_volume* volume, const char* path, uint8_t* buffer, size_t off,

View File

@@ -49,17 +49,16 @@ int memcmp (const void* s1, const void* s2, size_t n) {
void strtokenize (const char* str, char delim, void* ctx, strtokenize_cb_func_t cb) { void strtokenize (const char* str, char delim, void* ctx, strtokenize_cb_func_t cb) {
const char* start = str; const char* start = str;
const char* end;
while (*start) { while (*start) {
while (*start == delim && *start) while (*start && *start == delim)
start++; start++;
if (!*start) if (!*start)
break; break;
end = start; const char* end = start;
while (*end != delim && *end) while (*end && *end != delim)
end++; end++;
if (!cb (ctx, start, (size_t)(end - start))) if (!cb (ctx, start, (size_t)(end - start)))