DEADSOFTWARE

Fix memory corruption when load library
[mp3cc.git] / mpc / structures / block.c
index cb7b9d4bdf085b1e561905672b59464d49f72aef..1b55eeae2479366bf16c2474d8e1981b4ad7c303 100644 (file)
@@ -792,9 +792,10 @@ void read_library_file(FILE* library_file, unit* library_unit)
                        method->container_unit = library_unit;
                        method_name = string_create();
                        method_name->length = constant_pool[method_name_index].data_len;
-                       method_name->cstr = malloc(method_name->length + 1);
-                       strcpy(method_name->cstr, constant_pool[method_name_index].data);
-                       method_name->cstr[method_name->length] = '\0';
+                       // Strings in class has no null char
+                       method_name->cstr = malloc(method_name->length + 2);
+                       strncpy(method_name->cstr, constant_pool[method_name_index].data, method_name->length);
+                       method_name->cstr[method_name->length + 1] = '\0';
                        name_table_insert(library_unit->names, method_name, method);
                }