DEADSOFTWARE

Remove exception catching in main module
[mp3cc.git] / mpc / structures / block.c
index cb7b9d4bdf085b1e561905672b59464d49f72aef..0922765234cdd4ea50d81deb0b5c99e33bff40c4 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);
                }
 
@@ -2533,12 +2534,6 @@ void write_run_method(FILE *fp)
        /* create the code */
        bytecode_append(code, invokestatic$);
        bytecode_append_short_int(code, cp_add_methodref("M", "R", "()V"));
-
-       bytecode_append(code, goto$);
-       bytecode_append_short_int(code, 4);
-
-       bytecode_append(code, pop$);    /* the exception handler */
-
        bytecode_append(code, return$);
 
        /* write the method headers */
@@ -2557,13 +2552,14 @@ void write_run_method(FILE *fp)
 
        /* write the Code attribute */
        write_short_int(fp, cp_add_utf8("Code"));
-       write_long_int(fp, code->bytecode_pos + 20 + 38); /* 38 = stackmap size */
+       write_long_int(fp, code->bytecode_pos + 12);
 
        /* write the max stack */
        write_short_int(fp, 2);
 
        /* max locals for program block */
-       write_short_int(fp, 1);
+       write_short_int(fp, 2);
+
 
        /* code length */
        write_long_int(fp, code->bytecode_pos);
@@ -2574,70 +2570,8 @@ void write_run_method(FILE *fp)
 
        bytecode_destroy(code);
 
-       /* write exception table length*/
-       write_short_int(fp, 1);
-
-       /* write the exception table */
        write_short_int(fp, 0);
-       write_short_int(fp, 3);
-       write_short_int(fp, 6);
-       write_short_int(fp, cp_add_class("java/lang/Exception"));
-
-
-       /* StackMap attribute */
-       write_short_int(fp, 1);
-
-               write_short_int(fp, cp_add_utf8("StackMap"));
-               write_long_int(fp, 32);
-
-               /* 2 frames*/
-               write_short_int(fp, 3);
-
-               /* write the frame 0 */
-                       write_short_int(fp, 0);
-
-                       /* write the locals */
-                       write_short_int(fp, 1);
-                       tag = 7;
-                       if (fp != NULL)
-                               fwrite(&tag, 1, 1, fp);
-                       write_short_int(fp, cp_add_class("M"));
-
-
-                       /* 0 stack entries */
-                       write_short_int(fp, 0);
-
-               /* write the frame 1 */
-                       write_short_int(fp, 6);
-
-                       /* write the locals*/
-                       write_short_int(fp, 1);
-                       tag = 7;
-                       if (fp != NULL)
-                               fwrite(&tag, 1, 1, fp);
-                       write_short_int(fp, cp_add_class("M"));
-
-                       /* 1 stack entry */
-                       write_short_int(fp, 1);
-                       tag = 7;
-                       if (fp != NULL)
-                               fwrite(&tag, 1, 1, fp);
-                       write_short_int(fp, cp_add_class("java/lang/Exception"));
-
-
-               /* write the frame 2 */
-                       write_short_int(fp, 7);
-
-                       /* write the locals */
-                       write_short_int(fp, 1);
-                       tag = 7;
-                       if (fp != NULL)
-                               fwrite(&tag, 1, 1, fp);
-                       write_short_int(fp, cp_add_class("M"));
-
-                       /* 0 stack entries */
-                       write_short_int(fp, 0);
-
+       write_short_int(fp, 0);
 }