emote2ss

Animated webp to spritesheets converting tool
git clone git://bsandro.tech/emote2ss
Log | Files | Refs | README | LICENSE

commit a9fb16bf9a5104297363c4ecfd7210894f330120
parent afd88118a1d6e1c014fc9906eb3eb1b484b8d238
Author: bsandro <email@bsandro.tech>
Date:   Fri, 25 Aug 2023 00:14:19 +0300

input fields data reading fix

Diffstat:
Mgui/main.c | 12++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/gui/main.c b/gui/main.c @@ -254,12 +254,15 @@ int ButtonDialogSaveEvent(UIElement *element, UIMessage msg, int di, void *dp) { UITextbox *path_input = (UITextbox *)element->parent->children; UITextbox *filename_input = (UITextbox *)path_input->e.next; printf("path_input: %p\nfilename_input: %p\n", path_input, filename_input); - printf("path_input: %s(%d)\nfilename_input: %s(%d)\n", path_input->string, strlen(path_input->string), filename_input->string, strlen(filename_input->string)); + // that printf might work incorrectly because path_input->string might not contain valid C string with \0 at the end + printf("path_input: %s(%d)\nfilename_input: %s(%d)\n", path_input->string, path_input->bytes, filename_input->string, filename_input->bytes); int path_len = path_input->bytes + filename_input->bytes + 2; // DIR_SEPARATOR and '\0' printf("path_len: %d\n", path_len); char out_name[path_len]; + out_name[path_input->bytes] = DIR_SEPARATOR; out_name[path_len-1] = '\0'; - int n = snprintf(out_name, path_len, "%s%c%s", path_input->string, DIR_SEPARATOR, filename_input->string); + memcpy(out_name, path_input->string, path_input->bytes); + memcpy(out_name+path_input->bytes+1, filename_input->string, filename_input->bytes); printf("strlen(out_name): %d\n", strlen(out_name)); printf("out_name: %s\n", out_name); WebpWrite(out_name, img); @@ -283,9 +286,10 @@ int ButtonDialogOpenEvent(UIElement *element, UIMessage msg, int di, void *dp) { int path_len = path_input->bytes + filename_input->bytes + 2; // DIR_SEPARATOR and '\0' char filepath[path_len]; + filepath[path_input->bytes] = DIR_SEPARATOR; filepath[path_len-1] = '\0'; - int n = snprintf(filepath, path_len, "%s%c%s", path_input->string, DIR_SEPARATOR, filename_input->string); - assert(n>0); + memcpy(filepath, path_input->string, path_input->bytes); + memcpy(filepath+path_input->bytes+1, filename_input->string, filename_input->bytes); if (img != NULL) { ImageUnload(&img);