From dc68580fe311b7a0b4cae813a7bb5c767a67ae83 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:05:02 +0000 Subject: [PATCH 01/16] Added a new folder to ignore. Added the .vscode folder to be ignored. --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 238f253be..dc410f5ca 100644 --- a/.gitignore +++ b/.gitignore @@ -54,3 +54,5 @@ node_modules /*.tgz args.txt /other/benchs/hlc + +.vscode/ From 0217ed38ab1a6c339ccfcd5017e05718d7573e65 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:05:39 +0000 Subject: [PATCH 02/16] Initialized uninitialized array. Initialized the utf_chars array to an empty array. --- include/pcre/pcre_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pcre/pcre_compile.c b/include/pcre/pcre_compile.c index 6dd888606..cb92b7a96 100644 --- a/include/pcre/pcre_compile.c +++ b/include/pcre/pcre_compile.c @@ -4493,7 +4493,7 @@ dynamically as we process the pattern. */ /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */ BOOL utf = (options & PCRE_UTF8) != 0; #ifndef COMPILE_PCRE32 -pcre_uchar utf_chars[6]; +pcre_uchar utf_chars[6] = {}; #endif #else BOOL utf = FALSE; From 1e2096a4fa158d771c272a986ade4db09732b278 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:06:08 +0000 Subject: [PATCH 03/16] Removed unnecessary white space. Removed trailing whitespace after if clause. --- libs/mysql/my_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mysql/my_api.c b/libs/mysql/my_api.c index d606438bb..b9b599d6f 100644 --- a/libs/mysql/my_api.c +++ b/libs/mysql/my_api.c @@ -145,7 +145,7 @@ MYSQL *mysql_real_connect( MYSQL *m, const char *host, const char *user, const c myp_close(m); save_error(m,p); return NULL; - } + } m->infos.server_version = strdup(myp_read_string(p)); m->infos.thread_id = myp_read_int(p); myp_read(p,scramble_buf,8); From fcd3f4787ade4bd74f5664f1516f5e780000284b Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:07:24 +0000 Subject: [PATCH 04/16] Fixed switch case warnings. Added a missing FILED_TYPE_JSON filed to the enum_field_types enumeration. Changed the magic numbers in the switch case 246 and 245 for FILED_TYPE_NEWDECIMAL and FILED_TYPE_JSON respectively. --- libs/mysql/mysql.c | 4 ++-- libs/mysql/mysql.h | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/libs/mysql/mysql.c b/libs/mysql/mysql.c index 7f5337b5f..d24ad71d7 100644 --- a/libs/mysql/mysql.c +++ b/libs/mysql/mysql.c @@ -229,9 +229,9 @@ static CONV convert_type( enum enum_field_types t, int flags, unsigned int lengt case FIELD_TYPE_DECIMAL: case FIELD_TYPE_FLOAT: case FIELD_TYPE_DOUBLE: - case 246: // 5.0 MYSQL_NEW_DECIMAL + case FIELD_TYPE_NEWDECIMAL: // 5.0 MYSQL_NEW_DECIMAL return CONV_FLOAT; - case 245: // JSON + case FIELD_TYPE_JSON: // JSON return CONV_JSON; case FIELD_TYPE_BLOB: case FIELD_TYPE_TINY_BLOB: diff --git a/libs/mysql/mysql.h b/libs/mysql/mysql.h index a1c8127cd..b295efb33 100644 --- a/libs/mysql/mysql.h +++ b/libs/mysql/mysql.h @@ -47,6 +47,7 @@ typedef enum enum_field_types { FIELD_TYPE_NEWDATE = 0x0E, FIELD_TYPE_VARCHAR = 0x0F, FIELD_TYPE_BIT = 0x10, + FIELD_TYPE_JSON = 0xF5, FIELD_TYPE_NEWDECIMAL = 0xF6, FIELD_TYPE_ENUM = 0xF7, FIELD_TYPE_SET = 0xF8, From f73d7065dc435facaa6f8ccde18d226be094b4b6 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:09:10 +0000 Subject: [PATCH 05/16] Fixed warnings and missing returns. Added a return logic to the HL_NAME function based on SDL. Added missing casts to the HL_NAME implementation using hl_copy_bytes. --- libs/sdl/sdl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/sdl/sdl.c b/libs/sdl/sdl.c index 4a4e956c5..9929642a5 100644 --- a/libs/sdl/sdl.c +++ b/libs/sdl/sdl.c @@ -428,7 +428,7 @@ HL_PRIM void HL_NAME(set_window_grab)(SDL_Window* window, bool grabbed) { } HL_PRIM bool HL_NAME(get_window_grab)(SDL_Window* window) { - SDL_GetWindowGrab(window); + return SDL_GetWindowGrab(window); } HL_PRIM const char *HL_NAME(detect_keyboard_layout)() { @@ -831,9 +831,9 @@ HL_PRIM char* HL_NAME(get_clipboard_text)() { char* chr = SDL_GetClipboardText(); if (chr == NULL) return NULL; - vbyte* bytes = hl_copy_bytes(chr, (int) strlen(chr) + 1); + vbyte* bytes = hl_copy_bytes((vbyte*)chr, (int) strlen(chr) + 1); SDL_free(chr); - return bytes; + return (char*)bytes; } HL_PRIM varray* HL_NAME(get_displays)() { @@ -851,7 +851,7 @@ HL_PRIM varray* HL_NAME(get_displays)() { hl_dyn_seti(obj, hl_hash_utf8("top"), &hlt_i32, rect.y); hl_dyn_seti(obj, hl_hash_utf8("handle"), &hlt_i32, i); const char *name = SDL_GetDisplayName(i); - hl_dyn_setp(obj, hl_hash_utf8("name"), &hlt_bytes, hl_copy_bytes(name, (int) strlen(name)+1)); + hl_dyn_setp(obj, hl_hash_utf8("name"), &hlt_bytes, hl_copy_bytes((const vbyte*)name, (int) strlen(name)+1)); hl_aptr(arr, vdynamic*)[i] = obj; } return arr; From 985512837fb19bb76b99a30f6ba755836011982c Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:10:15 +0000 Subject: [PATCH 06/16] Added explicit cast. Added explicit cast for the function sqlite3_prepare16_v2 which expects a const void** as 5th argument instead of the const char** that tl represents. --- libs/sqlite/sqlite.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/sqlite/sqlite.c b/libs/sqlite/sqlite.c index 587465819..3893d323b 100644 --- a/libs/sqlite/sqlite.c +++ b/libs/sqlite/sqlite.c @@ -117,7 +117,7 @@ HL_PRIM sqlite_result *HL_NAME(request)(sqlite_database *db, vbyte *sql ) { r->finalize = HL_NAME(finalize_result); r->db = NULL; - if( sqlite3_prepare16_v2(db->db, sql, -1, &r->r, &tl) != SQLITE_OK ) { + if( sqlite3_prepare16_v2(db->db, sql, -1, &r->r, (const void **)&tl) != SQLITE_OK ) { HL_NAME(error)(db->db, false); } From 1dfe1235417d2eef0ee638375758d453da053681 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:11:17 +0000 Subject: [PATCH 07/16] Added missing parenthesis and null checks. Added missing parenthesis to suppress different types size warnings. Added an if clause in hl_free to avoid running through null pointers. --- src/gc.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index 1f1d773e3..24fd4d162 100644 --- a/src/gc.c +++ b/src/gc.c @@ -692,7 +692,7 @@ static void gc_mark() { hl_thread_info *t = gc_threads.threads[i]; cur_mark_stack = mark_stack; gc_mark_stack(t->stack_cur,t->stack_top); - gc_mark_stack(&t->gc_regs,(void**)&t->gc_regs + (sizeof(jmp_buf) / sizeof(void*) - 1)); + gc_mark_stack(&t->gc_regs,(void**)&t->gc_regs + (sizeof(jmp_buf) / (sizeof(void*)) - 1)); gc_mark_stack(&t->extra_stack_data,(void**)&t->extra_stack_data + t->extra_stack_size); mark_stack = cur_mark_stack; } @@ -878,7 +878,9 @@ void hl_free( hl_alloc *a ) { size = (int)(b->p + b->size - ((unsigned char*)b)); prev = (int_val)b; free(b); - b = n; + if (n) { + b = n; + } } // check if our allocator was not part of the last free block if( (int_val)a < prev || (int_val)a > prev+size ) From 8ec05ace686f6c69071f3533ba910dd6518c3c34 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:12:53 +0000 Subject: [PATCH 08/16] Changed addr type. Now addr type within hl_debug_read_register is vbyte* to prevent warnings in hl_debug_read in line 351. --- src/std/debug.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/debug.c b/src/std/debug.c index 03c88ed39..daae9059f 100644 --- a/src/std/debug.c +++ b/src/std/debug.c @@ -346,7 +346,7 @@ HL_API void *hl_debug_read_register( int pid, int thread, int reg, bool is64 ) { void *r = get_reg(reg); if( ((int_val)r) < 0 ) { // peek FP ptr - char *addr = (char*)ptrace(PTRACE_PEEKUSER,thread,get_reg(-1),0); + vbyte *addr = (vbyte*)ptrace(PTRACE_PEEKUSER,thread,get_reg(-1),0); void *out = NULL; hl_debug_read(pid, addr + (-((int_val)r)-1), (vbyte*)&out, sizeof(void*)); return out; From df28a43e0f5787588ac715e1b08eee815c634817 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:13:49 +0000 Subject: [PATCH 09/16] Moved logic to prevent NULL pointer access. Moved the "free(store);" line to after the "hl_remove_root(store);" line to prevent the use of a NULL pointer in hl_remove_root. --- src/std/thread.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/thread.c b/src/std/thread.c index 708cf59a8..330c8900b 100644 --- a/src/std/thread.c +++ b/src/std/thread.c @@ -503,8 +503,8 @@ HL_PRIM void hl_tls_set( hl_tls *l, void *v ) { _tls_set(l, store); } else { if( !v ) { - free(store); hl_remove_root(store); + free(store); _tls_set(l, NULL); return; } From c33f9a0b5fec90d31d0832676502291b1669d446 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:15:04 +0000 Subject: [PATCH 10/16] Added ustrdup logic. Added two ustrdup logic to prevent accidentally modifying the const uchar *str parameter. Copied this str to a local variable to modify said pointer locally and not modify str, as promised by the const identifier. --- src/std/ucs2.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/std/ucs2.c b/src/std/ucs2.c index 8dab11728..633729ff7 100644 --- a/src/std/ucs2.c +++ b/src/std/ucs2.c @@ -80,7 +80,8 @@ double utod( const uchar *str, uchar **end ) { } buf[i] = 0; result = strtod(buf,&bend); - *end = str + (bend - buf); + uchar *strcpy = ustrdup(str); + *end = strcpy + (bend - buf); return result; } @@ -101,7 +102,8 @@ int utoi( const uchar *str, uchar **end ) { } buf[i] = 0; result = strtol(buf,&bend,10); - *end = str + (bend - buf); + uchar *strcpy = ustrdup(str); + *end = strcpy + (bend - buf); return result; } From 66ac586d110c946a6d33fd9e713c29236b527aeb Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:17:52 +0000 Subject: [PATCH 11/16] Added explicit cast. Now the send function is explicitly casted to int. --- libs/mysql/socket.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/mysql/socket.c b/libs/mysql/socket.c index 51ab16579..3c29738e9 100644 --- a/libs/mysql/socket.c +++ b/libs/mysql/socket.c @@ -98,7 +98,7 @@ void psock_close( PSOCK s ) { int psock_send( PSOCK s, const char *buf, int size ) { int ret; POSIX_LABEL(send_again); - ret = send(s,buf,size,MSG_NOSIGNAL); + ret = (int)send(s,buf,size,MSG_NOSIGNAL); if( ret == SOCKET_ERROR ) { HANDLE_EINTR(send_again); return block_error(); From 9b9de0082462a46a8e406c2c19557bdb466b8b17 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 14:49:59 +0000 Subject: [PATCH 12/16] Fixed warning on cast. Now the integer is first cast into a long integer to make the cast to vbyte* be of equivalent size. --- src/std/bytes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/std/bytes.c b/src/std/bytes.c index 55dd296da..32597d626 100644 --- a/src/std/bytes.c +++ b/src/std/bytes.c @@ -254,7 +254,7 @@ HL_PRIM vbyte *hl_bytes_from_address( int low, int high ) { i64.high = high; return *(vbyte**)&i64; # else - return (vbyte*)low; + return (vbyte*)(long)low; # endif } From 9722386c841a7b2014c9c37e4e9c1c76337ab54c Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 15:11:21 +0000 Subject: [PATCH 13/16] Fixed naming and unnecessary comments. Now the variable does not have the same name as the C function. Removed unnecessary comments. --- libs/mysql/mysql.c | 4 ++-- src/std/ucs2.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libs/mysql/mysql.c b/libs/mysql/mysql.c index d24ad71d7..7ede2df68 100644 --- a/libs/mysql/mysql.c +++ b/libs/mysql/mysql.c @@ -229,9 +229,9 @@ static CONV convert_type( enum enum_field_types t, int flags, unsigned int lengt case FIELD_TYPE_DECIMAL: case FIELD_TYPE_FLOAT: case FIELD_TYPE_DOUBLE: - case FIELD_TYPE_NEWDECIMAL: // 5.0 MYSQL_NEW_DECIMAL + case FIELD_TYPE_NEWDECIMAL: return CONV_FLOAT; - case FIELD_TYPE_JSON: // JSON + case FIELD_TYPE_JSON: return CONV_JSON; case FIELD_TYPE_BLOB: case FIELD_TYPE_TINY_BLOB: diff --git a/src/std/ucs2.c b/src/std/ucs2.c index 633729ff7..73a7c7d6a 100644 --- a/src/std/ucs2.c +++ b/src/std/ucs2.c @@ -80,8 +80,8 @@ double utod( const uchar *str, uchar **end ) { } buf[i] = 0; result = strtod(buf,&bend); - uchar *strcpy = ustrdup(str); - *end = strcpy + (bend - buf); + uchar *new_str = ustrdup(str); + *end = new_str + (bend - buf); return result; } From da0ea984ff1a39ec1cb8fda09193d15baba22e94 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 15:13:26 +0000 Subject: [PATCH 14/16] Improved name and fixed second instance. Fixed second instance of using a C function name as a variable name. Improved the naming of the copied str. --- src/std/ucs2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/std/ucs2.c b/src/std/ucs2.c index 73a7c7d6a..a81be24e8 100644 --- a/src/std/ucs2.c +++ b/src/std/ucs2.c @@ -80,8 +80,8 @@ double utod( const uchar *str, uchar **end ) { } buf[i] = 0; result = strtod(buf,&bend); - uchar *new_str = ustrdup(str); - *end = new_str + (bend - buf); + uchar *copied_str = ustrdup(str); + *end = copied_str + (bend - buf); return result; } @@ -102,8 +102,8 @@ int utoi( const uchar *str, uchar **end ) { } buf[i] = 0; result = strtol(buf,&bend,10); - uchar *strcpy = ustrdup(str); - *end = strcpy + (bend - buf); + uchar *copied_str = ustrdup(str); + *end = copied_str + (bend - buf); return result; } From 418b8663086854ac1ee9ee6646ab30ccd765670d Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 21:18:50 +0000 Subject: [PATCH 15/16] Reverted breaking change. Reverted if statement to prevent breaking changes. --- src/gc.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/gc.c b/src/gc.c index 24fd4d162..93d3f49d5 100644 --- a/src/gc.c +++ b/src/gc.c @@ -878,9 +878,7 @@ void hl_free( hl_alloc *a ) { size = (int)(b->p + b->size - ((unsigned char*)b)); prev = (int_val)b; free(b); - if (n) { - b = n; - } + b = n; } // check if our allocator was not part of the last free block if( (int_val)a < prev || (int_val)a > prev+size ) From 6cb438ff27ecc57f6924394ad498fbd128fb05c1 Mon Sep 17 00:00:00 2001 From: Victor Matia Date: Tue, 31 Jan 2023 23:17:16 +0000 Subject: [PATCH 16/16] Added proper C array initialization. Explicitly added a 0 in the array initialization to prevent MSVC errors. --- include/pcre/pcre_compile.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/pcre/pcre_compile.c b/include/pcre/pcre_compile.c index cb92b7a96..c6b5ff1df 100644 --- a/include/pcre/pcre_compile.c +++ b/include/pcre/pcre_compile.c @@ -4493,7 +4493,7 @@ dynamically as we process the pattern. */ /* PCRE_UTF[16|32] have the same value as PCRE_UTF8. */ BOOL utf = (options & PCRE_UTF8) != 0; #ifndef COMPILE_PCRE32 -pcre_uchar utf_chars[6] = {}; +pcre_uchar utf_chars[6] = {0}; #endif #else BOOL utf = FALSE;