Consoludate array functions
authorRobert Pengelly <robertapengelly@hotmail.com>
Fri, 10 Oct 2025 05:56:44 +0000 (06:56 +0100)
committerRobert Pengelly <robertapengelly@hotmail.com>
Fri, 10 Oct 2025 05:59:30 +0000 (06:59 +0100)
aout.c
coff.c
elks.c
ld.c
lib.c
lib.h
link.c
mz.c
omf.c
pe.c

diff --git a/aout.c b/aout.c
index 5f676a77649b5006ddbb1e369357f72727a9de0c..dc72090487e21b00a37820823d04a0c6bcd69526 100644 (file)
--- a/aout.c
+++ b/aout.c
@@ -16,9 +16,9 @@ static unsigned long section_alignment = DEFAULT_SECTION_ALIGNMENT;
 
 static void translate_relocation (struct reloc_entry *reloc, struct aout_relocation_info *input_reloc, struct section_part *part, struct aout_exec *exec_p) {
 
-    unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4);
+    unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4, 0);
     
-    unsigned long r_address = array_to_integer (input_reloc->r_address, 4);
+    unsigned long r_address = array_to_integer (input_reloc->r_address, 4, 0);
     long symbolnum = (r_symbolnum & 0xffffff);
     
     if ((r_symbolnum >> 27) & 1) {      /* ext */
@@ -38,12 +38,12 @@ static void translate_relocation (struct reloc_entry *reloc, struct aout_relocat
         } else if (symbolnum == N_DATA) {
         
             reloc->symbol = part->of->symbol_arr + part->of->symbol_cnt - 2;
-            reloc->addend -= array_to_integer (exec_p->a_text, 4);
+            reloc->addend -= array_to_integer (exec_p->a_text, 4, 0);
         
         } else if (symbolnum == N_BSS) {
         
             reloc->symbol = part->of->symbol_arr + part->of->symbol_cnt - 1;
-            reloc->addend -= (array_to_integer (exec_p->a_text, 4) + array_to_integer (exec_p->a_data, 4));
+            reloc->addend -= (array_to_integer (exec_p->a_text, 4, 0) + array_to_integer (exec_p->a_data, 4, 0));
         
         } else {
         
@@ -153,7 +153,7 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     aout_exec = (struct aout_exec *) pos;
     pos += sizeof (*aout_exec);
     
-    num_symbols = array_to_integer (aout_exec->a_syms, 4) / sizeof (*aout_nlist);
+    num_symbols = array_to_integer (aout_exec->a_syms, 4, 0) / sizeof (*aout_nlist);
     of = object_file_make (filename, num_symbols + 4);
     
     section = section_find_or_make (".text");
@@ -161,7 +161,7 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     part = section_part_new (section, of);
     
-    part->content_size = array_to_integer (aout_exec->a_text, 4);
+    part->content_size = array_to_integer (aout_exec->a_text, 4, 0);
     part->content = xmalloc (part->content_size);
     
     if ((pos - data + part->content_size > data_size) || pos < data) {
@@ -182,7 +182,7 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     part = section_part_new (section, of);
     
-    part->content_size = array_to_integer (aout_exec->a_data, 4);
+    part->content_size = array_to_integer (aout_exec->a_data, 4, 0);
     part->content = xmalloc (part->content_size);
     
     if ((pos - data + part->content_size > data_size) || pos < data) {
@@ -204,12 +204,12 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     section->is_bss = 1;
     
     part = section_part_new (section, of);
-    part->content_size = array_to_integer (aout_exec->a_bss, 4);
+    part->content_size = array_to_integer (aout_exec->a_bss, 4, 0);
     
     section_append_section_part (section, part);
     part_p_array[3] = part;
     
-    pos += array_to_integer (aout_exec->a_syms, 4) + array_to_integer (aout_exec->a_trsize, 4) + array_to_integer (aout_exec->a_drsize, 4);
+    pos += array_to_integer (aout_exec->a_syms, 4, 0) + array_to_integer (aout_exec->a_trsize, 4, 0) + array_to_integer (aout_exec->a_drsize, 4, 0);
     
     if ((unsigned long) (pos - data + 4) > data_size || pos < data) {
     
@@ -218,7 +218,7 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    strtab_size = array_to_integer (pos, 4);
+    strtab_size = array_to_integer (pos, 4, 0);
     
     if (strtab_size < 4) {
     
@@ -238,15 +238,15 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos -= array_to_integer (aout_exec->a_syms, 4);
+    pos -= array_to_integer (aout_exec->a_syms, 4, 0);
     
     for (i = 0; i < num_symbols; i++) {
     
         aout_nlist = (struct aout_nlist *) (pos + (i * sizeof (*aout_nlist)));
         symbol = of->symbol_arr + i;
         
-        if (array_to_integer (aout_nlist->n_strx, 4) < strtab_size) {
-            symbol->name = xstrdup (strtab + array_to_integer (aout_nlist->n_strx, 4));
+        if (array_to_integer (aout_nlist->n_strx, 4, 0) < strtab_size) {
+            symbol->name = xstrdup (strtab + array_to_integer (aout_nlist->n_strx, 4, 0));
         } else {
         
             report_at (program_name, 0, REPORT_FATAL_ERROR, "%s: invalid offset into string table", filename);
@@ -254,7 +254,7 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
         
         }
         
-        symbol->value = array_to_integer (aout_nlist->n_value, 4);
+        symbol->value = array_to_integer (aout_nlist->n_value, 4, 0);
         symbol->size = 0;
         symbol->n_type = aout_nlist->n_type;
         
@@ -308,13 +308,13 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
         
             symbol->section_number = 2;
             symbol->part = part_p_array[2];
-            symbol->value -= array_to_integer (aout_exec->a_text, 4);
+            symbol->value -= array_to_integer (aout_exec->a_text, 4, 0);
         
         } else if ((aout_nlist->n_type & N_TYPE) == N_BSS) {
         
             symbol->section_number = 3;
             symbol->part = part_p_array[3];
-            symbol->value -= (array_to_integer (aout_exec->a_text, 4) + array_to_integer (aout_exec->a_data, 4));
+            symbol->value -= (array_to_integer (aout_exec->a_text, 4, 0) + array_to_integer (aout_exec->a_data, 4, 0));
         
         } else {
         
@@ -342,10 +342,10 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos -= (array_to_integer (aout_exec->a_trsize, 4) + array_to_integer (aout_exec->a_drsize, 4));
+    pos -= (array_to_integer (aout_exec->a_trsize, 4, 0) + array_to_integer (aout_exec->a_drsize, 4, 0));
     part = part_p_array[1];
     
-    part->reloc_cnt = array_to_integer (aout_exec->a_trsize, 4) / sizeof (*reloc_info);
+    part->reloc_cnt = array_to_integer (aout_exec->a_trsize, 4, 0) / sizeof (*reloc_info);
     part->reloc_arr = xmalloc (sizeof (*part->reloc_arr) * part->reloc_cnt);
     
     for (i = 0; i < part->reloc_cnt; i++) {
@@ -355,10 +355,10 @@ void read_aout_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos += array_to_integer (aout_exec->a_trsize, 4);
+    pos += array_to_integer (aout_exec->a_trsize, 4, 0);
     part = part_p_array[2];
     
-    part->reloc_cnt = array_to_integer (aout_exec->a_drsize, 4) / sizeof (*reloc_info);
+    part->reloc_cnt = array_to_integer (aout_exec->a_drsize, 4, 0) / sizeof (*reloc_info);
     part->reloc_arr = xmalloc (sizeof (*part->reloc_arr) * part->reloc_cnt);
     
     for (i = 0; i < part->reloc_cnt; i++) {
@@ -428,7 +428,7 @@ static unsigned char *write_relocs_for_section (unsigned char *pos, struct secti
                 symbol = symbol_find (symbol->name);
             }
             
-            integer_to_array (part->rva - part->section->rva + part->reloc_arr[i].offset, rel.r_address, 4);
+            integer_to_array (part->rva - part->section->rva + part->reloc_arr[i].offset, rel.r_address, 4, 0);
             
             if (!symbol->part || strcmp (symbol->part->section->name, ".text") == 0) {
                 r_symbolnum = N_TEXT;
@@ -447,7 +447,7 @@ static unsigned char *write_relocs_for_section (unsigned char *pos, struct secti
             
             }
             
-            integer_to_array (r_symbolnum | (size_log2 << 25), rel.r_symbolnum, 4);
+            integer_to_array (r_symbolnum | (size_log2 << 25), rel.r_symbolnum, 4, 0);
             
             memcpy (pos, &rel, sizeof (rel));
             pos += sizeof (rel);
@@ -484,7 +484,7 @@ void aout_write (const char *filename) {
     data_section = section_find (".data");
     bss_section  = section_find (".bss");
     
-    integer_to_array (OMAGIC, exec.a_info, 4);
+    integer_to_array (OMAGIC, exec.a_info, 4, 0);
     
     if (text_section) {
     
@@ -516,24 +516,24 @@ void aout_write (const char *filename) {
     
     }
     
-    integer_to_array (text_size, exec.a_text, 4);
-    integer_to_array (data_size, exec.a_data, 4);
+    integer_to_array (text_size, exec.a_text, 4, 0);
+    integer_to_array (data_size, exec.a_data, 4, 0);
     
-    integer_to_array (bss_size, exec.a_bss, 4);
-    integer_to_array (state->entry_point, exec.a_entry, 4);
+    integer_to_array (bss_size, exec.a_bss, 4, 0);
+    integer_to_array (state->entry_point, exec.a_entry, 4, 0);
     
     if (text_section) {
-        integer_to_array (section_get_num_relocs (text_section) * sizeof (struct aout_relocation_info), exec.a_trsize, 4);
+        integer_to_array (section_get_num_relocs (text_section) * sizeof (struct aout_relocation_info), exec.a_trsize, 4, 0);
     }
     
     if (data_section) {
-        integer_to_array (section_get_num_relocs (data_section) * sizeof (struct aout_relocation_info), exec.a_drsize, 4);
+        integer_to_array (section_get_num_relocs (data_section) * sizeof (struct aout_relocation_info), exec.a_drsize, 4, 0);
     }
     
     image_size = sizeof (exec);
     
-    image_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
-    image_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
+    image_size += (array_to_integer (exec.a_text, 4, 0) + array_to_integer (exec.a_data, 4, 0));
+    image_size += (array_to_integer (exec.a_trsize, 4, 0) + array_to_integer (exec.a_drsize, 4, 0));
     
     image_size += 4;
     
@@ -546,13 +546,13 @@ void aout_write (const char *filename) {
         section_write (text_section, pos);
     }
     
-    pos += array_to_integer (exec.a_text, 4);
+    pos += array_to_integer (exec.a_text, 4, 0);
     
     if (data_section) {
         section_write (data_section, pos);
     }
     
-    pos += array_to_integer (exec.a_data, 4);
+    pos += array_to_integer (exec.a_data, 4, 0);
     
     if (text_section) {
         pos = write_relocs_for_section (pos, text_section);
@@ -562,7 +562,7 @@ void aout_write (const char *filename) {
         pos = write_relocs_for_section (pos, data_section);
     }
     
-    integer_to_array (4, pos, 4);
+    integer_to_array (4, pos, 4, 0);
     
     if (fwrite (data, image_size, 1, fp) != 1) {
         report_at (program_name, 0, REPORT_ERROR, "failed to write data to '%s'", filename);
diff --git a/coff.c b/coff.c
index 96b51eef36c19c1b60e2e5cbcd72285a6a3070d5..12f4cb59c3cd2c6302930d1fa22035101ab44b45 100644 (file)
--- a/coff.c
+++ b/coff.c
@@ -44,10 +44,10 @@ struct symbol_table_entry {
 
 static void translate_relocation (struct reloc_entry *reloc, struct coff_relocation_entry *input, struct section_part *part) {
 
-    reloc->symbol = part->of->symbol_arr + array_to_integer (input->SymbolTableIndex, 4);
-    reloc->offset = array_to_integer (input->VirtualAddress, 4);
+    reloc->symbol = part->of->symbol_arr + array_to_integer (input->SymbolTableIndex, 4, 0);
+    reloc->offset = array_to_integer (input->VirtualAddress, 4, 0);
     
-    switch (array_to_integer (input->Type, 2)) {
+    switch (array_to_integer (input->Type, 2, 0)) {
     
         case IMAGE_REL_I386_ABSOLUTE:
         
@@ -82,7 +82,7 @@ static void translate_relocation (struct reloc_entry *reloc, struct coff_relocat
         default:
         
             /* There is no point in continuing, the object is broken. */
-            report_at (program_name, 0, REPORT_FATAL_ERROR, "invalid relocation type 0x%04hx (origin object '%s')", array_to_integer (input->Type, 2), part->of->filename);
+            report_at (program_name, 0, REPORT_FATAL_ERROR, "invalid relocation type 0x%04hx (origin object '%s')", array_to_integer (input->Type, 2, 0), part->of->filename);
             exit (EXIT_FAILURE);
     
     }
@@ -236,10 +236,10 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
     
     coff_hdr = (struct coff_header *) data;
     
-    pos = (unsigned char *) data + array_to_integer (coff_hdr->PointerToSymbolTable, 4) + sizeof (struct symbol_table_entry) * array_to_integer (coff_hdr->NumberOfSymbols, 4);
+    pos = (unsigned char *) data + array_to_integer (coff_hdr->PointerToSymbolTable, 4, 0) + sizeof (struct symbol_table_entry) * array_to_integer (coff_hdr->NumberOfSymbols, 4, 0);
     string_table_hdr = (struct string_table_header *) pos;
     
-    if ((string_table_size = array_to_integer (string_table_hdr->StringTableSize, 4)) < 4) {
+    if ((string_table_size = array_to_integer (string_table_hdr->StringTableSize, 4, 0)) < 4) {
     
         report_at (program_name, 0, REPORT_ERROR, "%s: invalid string table size: %lu", filename, string_table_size);
         return;
@@ -248,10 +248,10 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
     
     string_table = (char *) pos;
     
-    part_p_array = xmalloc (sizeof (*part_p_array) * (array_to_integer (coff_hdr->NumberOfSections, 2) + 1));
-    of = object_file_make (filename, array_to_integer (coff_hdr->NumberOfSymbols, 4));
+    part_p_array = xmalloc (sizeof (*part_p_array) * (array_to_integer (coff_hdr->NumberOfSections, 2, 0) + 1));
+    of = object_file_make (filename, array_to_integer (coff_hdr->NumberOfSymbols, 4, 0));
     
-    no_sections = array_to_integer (coff_hdr->NumberOfSections, 2);
+    no_sections = array_to_integer (coff_hdr->NumberOfSections, 2, 0);
     
     for (i = 0; i < no_sections; i++) {
     
@@ -262,7 +262,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         
             unsigned long offset = strtoul (section_name + 1, NULL, 10);
             
-            if (offset < array_to_integer (string_table_hdr->StringTableSize, 4)) {
+            if (offset < array_to_integer (string_table_hdr->StringTableSize, 4, 0)) {
             
                 free (section_name);
                 section_name = xstrdup (string_table + offset);
@@ -279,7 +279,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         
         if (state->format == LD_FORMAT_I386_PE && strcmp (section_name, ".drectve") == 0) {
         
-            pe_interpret_dot_drectve_section (/*filename, data, data_size, */data + array_to_integer (section_hdr->PointerToRawData, 4), array_to_integer (section_hdr->SizeOfRawData, 4));
+            pe_interpret_dot_drectve_section (/*filename, data, data_size, */data + array_to_integer (section_hdr->PointerToRawData, 4, 0), array_to_integer (section_hdr->SizeOfRawData, 4, 0));
             
             part_p_array[i + 1] = 0;
             free (section_name);
@@ -288,7 +288,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         
         }
         
-        if (array_to_integer (section_hdr->Characteristics, 4) & IMAGE_SCN_LNK_REMOVE) {
+        if (array_to_integer (section_hdr->Characteristics, 4, 0) & IMAGE_SCN_LNK_REMOVE) {
         
             part_p_array[i + 1] = 0;
             
@@ -298,9 +298,9 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         }
         
         section = section_find_or_make (section_name);
-        section->flags = translate_Characteristics_to_section_flags (array_to_integer (section_hdr->Characteristics, 4));
+        section->flags = translate_Characteristics_to_section_flags (array_to_integer (section_hdr->Characteristics, 4, 0));
         
-        if (array_to_integer (section_hdr->PointerToRawData, 4) == 0 && array_to_integer (section_hdr->SizeOfRawData, 4)) {
+        if (array_to_integer (section_hdr->PointerToRawData, 4, 0) == 0 && array_to_integer (section_hdr->SizeOfRawData, 4, 0)) {
             section->is_bss = 1;
         }
         
@@ -313,12 +313,12 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         free (section_name);
         
         part = section_part_new (section, of);
-        part->alignment = translate_Characteristics_to_alignment (array_to_integer (section_hdr->Characteristics, 4));
-        part->content_size = array_to_integer (section_hdr->SizeOfRawData, 4);
+        part->alignment = translate_Characteristics_to_alignment (array_to_integer (section_hdr->Characteristics, 4, 0));
+        part->content_size = array_to_integer (section_hdr->SizeOfRawData, 4, 0);
         
-        if (array_to_integer (section_hdr->PointerToRawData, 4)) {
+        if (array_to_integer (section_hdr->PointerToRawData, 4, 0)) {
         
-            pos = (unsigned char *) data + array_to_integer (section_hdr->PointerToRawData, 4);
+            pos = (unsigned char *) data + array_to_integer (section_hdr->PointerToRawData, 4, 0);
             
             part->content = xmalloc (part->content_size);
             memcpy (part->content, pos, part->content_size);
@@ -332,23 +332,23 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         
         }
         
-        if (array_to_integer (section_hdr->PointerToRelocations, 4) && array_to_integer (section_hdr->NumberOfRelocations, 2)) {
+        if (array_to_integer (section_hdr->PointerToRelocations, 4, 0) && array_to_integer (section_hdr->NumberOfRelocations, 2, 0)) {
         
             unsigned long j, no_relocs;
             
-            if (!array_to_integer (section_hdr->PointerToRawData, 4)) {
+            if (!array_to_integer (section_hdr->PointerToRawData, 4, 0)) {
             
                 report_at (program_name, 0, REPORT_FATAL_ERROR, "%s: section '%s' is BSS but has relocations", filename, section->name);
                 exit (EXIT_FAILURE);
             
             }
             
-            pos = (unsigned char *) data + array_to_integer (section_hdr->PointerToRelocations, 4);
+            pos = (unsigned char *) data + array_to_integer (section_hdr->PointerToRelocations, 4, 0);
             
-            part->reloc_arr = xmalloc (sizeof (struct reloc_entry) * array_to_integer (section_hdr->NumberOfRelocations, 2));
-            part->reloc_cnt = array_to_integer (section_hdr->NumberOfRelocations, 2);
+            part->reloc_arr = xmalloc (sizeof (struct reloc_entry) * array_to_integer (section_hdr->NumberOfRelocations, 2, 0));
+            part->reloc_cnt = array_to_integer (section_hdr->NumberOfRelocations, 2, 0);
             
-            no_relocs = array_to_integer (section_hdr->NumberOfRelocations, 2);
+            no_relocs = array_to_integer (section_hdr->NumberOfRelocations, 2, 0);
             
             for (j = 0; j < no_relocs; j++) {
             
@@ -369,7 +369,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    no_syms = array_to_integer (coff_hdr->NumberOfSymbols, 4);
+    no_syms = array_to_integer (coff_hdr->NumberOfSymbols, 4, 0);
     
     for (i = 0; i < no_syms; i++) {
     
@@ -378,13 +378,13 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
         struct symbol_table_entry *coff_symbol;
         short section_no, no_sections;
         
-        coff_symbol = (struct symbol_table_entry *) ((unsigned char *) data + array_to_integer (coff_hdr->PointerToSymbolTable, 4) + sizeof (struct symbol_table_entry) * i);
+        coff_symbol = (struct symbol_table_entry *) ((unsigned char *) data + array_to_integer (coff_hdr->PointerToSymbolTable, 4, 0) + sizeof (struct symbol_table_entry) * i);
         
         if (memcmp (coff_symbol->Name, "\0\0\0\0", 4) == 0) {
         
-            unsigned long offset = array_to_integer (coff_symbol->Name + 4, 4);
+            unsigned long offset = array_to_integer (coff_symbol->Name + 4, 4, 0);
             
-            if (offset < array_to_integer (string_table_hdr->StringTableSize, 4)) {
+            if (offset < array_to_integer (string_table_hdr->StringTableSize, 4, 0)) {
                 symbol->name = xstrdup (string_table + offset);
             } else {
             
@@ -397,13 +397,13 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
             symbol->name = xstrndup ((char *) coff_symbol->Name, 8);
         }
         
-        section_no = array_to_integer (coff_symbol->SectionNumber, 2);
+        section_no = array_to_integer (coff_symbol->SectionNumber, 2, 0);
         
-        symbol->value = array_to_integer (coff_symbol->value, 4);
+        symbol->value = array_to_integer (coff_symbol->value, 4, 0);
         symbol->size = 0;
         symbol->section_number = section_no;
         
-        no_sections = array_to_integer (coff_hdr->NumberOfSections, 2);
+        no_sections = array_to_integer (coff_hdr->NumberOfSections, 2, 0);
         
         if (section_no == IMAGE_SYM_UNDEFINED) {
         
@@ -420,7 +420,7 @@ void read_coff_object (const char *filename, unsigned char *data, unsigned long
                         bss_section->flags = translate_Characteristics_to_section_flags (IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ | IMAGE_SCN_MEM_WRITE);
                         bss_section->is_bss = 1;
                         
-                        bss_section_number = array_to_integer (coff_hdr->NumberOfSections, 2) ? array_to_integer (coff_hdr->NumberOfSections, 2) : 1;
+                        bss_section_number = array_to_integer (coff_hdr->NumberOfSections, 2, 0) ? array_to_integer (coff_hdr->NumberOfSections, 2, 0) : 1;
                     
                     }
                     
@@ -601,12 +601,12 @@ static void generate_base_relocation_block (struct section *section, struct coff
         
         for (i = ((part == saved_part) ? saved_i : 0); i < part->reloc_cnt; i++) {
         
-            integer_to_array (part->rva + relocs[i].offset, ibr_hdr_p->VirtualAddress, 4);
+            integer_to_array (part->rva + relocs[i].offset, ibr_hdr_p->VirtualAddress, 4, 0);
             
             if (relocs[i].howto == &reloc_howtos[RELOC_TYPE_16]) {
-                integer_to_array (IMAGE_REL_I386_DIR16, ibr_hdr_p->Type, 2);
+                integer_to_array (IMAGE_REL_I386_DIR16, ibr_hdr_p->Type, 2, 0);
             } else if (relocs[i].howto == &reloc_howtos[RELOC_TYPE_32]) {
-                integer_to_array (IMAGE_REL_I386_DIR32, ibr_hdr_p->Type, 2);
+                integer_to_array (IMAGE_REL_I386_DIR32, ibr_hdr_p->Type, 2, 0);
             } else {
                 continue;
             }
@@ -708,12 +708,12 @@ static void write_sections (unsigned char *data) {
             write741_to_byte_array (hdr->SizeOfRawData, section->total_size);
             write741_to_byte_array (hdr->PointerToRawData, pos - data);
             
-            if (array_to_integer (hdr->NumberOfRelocations, 2) > 0) {
+            if (array_to_integer (hdr->NumberOfRelocations, 2, 0) > 0) {
                 write741_to_byte_array (hdr->PointerToRelocations, (pos - data) + section->total_size);
             }
             
             section_write (section, pos);
-            pos += (section->total_size + (array_to_integer (hdr->NumberOfRelocations, 2) * sizeof (struct coff_relocation_entry)));
+            pos += (section->total_size + (array_to_integer (hdr->NumberOfRelocations, 2, 0) * sizeof (struct coff_relocation_entry)));
         
         }
         
@@ -723,21 +723,21 @@ static void write_sections (unsigned char *data) {
         if (characteristics & IMAGE_SCN_CNT_CODE) {
         
             if (!base_of_code) {
-                base_of_code = array_to_integer (hdr->VirtualAddress, 4);
+                base_of_code = array_to_integer (hdr->VirtualAddress, 4, 0);
             }
             
-            size_of_code += array_to_integer (hdr->VirtualSize, 4);
+            size_of_code += array_to_integer (hdr->VirtualSize, 4, 0);
         
         } else if (characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) {
         
             if (!base_of_data) {
-                base_of_data = array_to_integer (hdr->VirtualAddress, 4);
+                base_of_data = array_to_integer (hdr->VirtualAddress, 4, 0);
             }
             
-            size_of_initialized_data += array_to_integer (hdr->VirtualSize, 4);
+            size_of_initialized_data += array_to_integer (hdr->VirtualSize, 4, 0);
         
         } else if (characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) {
-            size_of_uninitialized_data += array_to_integer (hdr->VirtualSize, 4);
+            size_of_uninitialized_data += array_to_integer (hdr->VirtualSize, 4, 0);
         }
         
         last_section = section;
@@ -778,7 +778,7 @@ void coff_after_link (void) {
                     continue;
                 }
                 
-                if (num_relocs && part->rva + relocs[i].offset < array_to_integer (ibr_hdr.VirtualAddress, 4)) {
+                if (num_relocs && part->rva + relocs[i].offset < array_to_integer (ibr_hdr.VirtualAddress, 4, 0)) {
                 
                     generate_base_relocation_block (section, &ibr_hdr, num_relocs, saved_section, saved_part, saved_i);
                     num_relocs = 0;
@@ -787,7 +787,7 @@ void coff_after_link (void) {
                 
                 if (num_relocs == 0) {
                 
-                    integer_to_array (part->rva + relocs[i].offset, ibr_hdr.VirtualAddress, 4);
+                    integer_to_array (part->rva + relocs[i].offset, ibr_hdr.VirtualAddress, 4, 0);
                     
                     saved_section = section;
                     saved_part = part;
@@ -806,7 +806,7 @@ void coff_after_link (void) {
             generate_base_relocation_block (section, &ibr_hdr, num_relocs, saved_section, saved_part, saved_i);
         }
         
-        integer_to_array (num_relocs, hdr->NumberOfRelocations, 2);
+        integer_to_array (num_relocs, hdr->NumberOfRelocations, 2, 0);
     
     }
 
@@ -859,7 +859,7 @@ void coff_write (const char *filename) {
             data_size += section->total_size;
             
             if ((sec_ent = section->object_dependent_data)) {
-                data_size += (array_to_integer (sec_ent->NumberOfRelocations, 2) * sizeof (struct coff_relocation_entry));
+                data_size += (array_to_integer (sec_ent->NumberOfRelocations, 2, 0) * sizeof (struct coff_relocation_entry));
             }
         
         }
diff --git a/elks.c b/elks.c
index a46c69a31baf399db6fca3f481bfea07dd178db8..0dbfe7faec7d33ffa157827c17438fa5f010b999 100644 (file)
--- a/elks.c
+++ b/elks.c
@@ -17,9 +17,9 @@ static unsigned long section_alignment = DEFAULT_SECTION_ALIGNMENT;
 
 static void translate_relocation (struct reloc_entry *reloc, struct elks_relocation_info *input_reloc, struct section_part *part, struct elks_exec *exec_p) {
 
-    unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4);
+    unsigned long r_symbolnum = array_to_integer (input_reloc->r_symbolnum, 4, 0);
     
-    unsigned long r_address = array_to_integer (input_reloc->r_address, 4);
+    unsigned long r_address = array_to_integer (input_reloc->r_address, 4, 0);
     long symbolnum = (r_symbolnum & 0x7ffffff);
     
     if ((r_symbolnum >> 31) & 1) {      /* ext */
@@ -39,12 +39,12 @@ static void translate_relocation (struct reloc_entry *reloc, struct elks_relocat
         } else if (symbolnum == N_DATA) {
         
             reloc->symbol = part->of->symbol_arr + part->of->symbol_cnt - 2;
-            reloc->addend -= array_to_integer (exec_p->a_text, 4);
+            reloc->addend -= array_to_integer (exec_p->a_text, 4, 0);
         
         } else if (symbolnum == N_BSS) {
         
             reloc->symbol = part->of->symbol_arr + part->of->symbol_cnt - 1;
-            reloc->addend -= (array_to_integer (exec_p->a_text, 4) + array_to_integer (exec_p->a_data, 4));
+            reloc->addend -= (array_to_integer (exec_p->a_text, 4, 0) + array_to_integer (exec_p->a_data, 4, 0));
         
         } else {
         
@@ -154,7 +154,7 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     elks_exec = (struct elks_exec *) pos;
     pos += sizeof (*elks_exec);
     
-    num_symbols = array_to_integer (elks_exec->a_syms, 4) / sizeof (*elks_nlist);
+    num_symbols = array_to_integer (elks_exec->a_syms, 4, 0) / sizeof (*elks_nlist);
     of = object_file_make (filename, num_symbols + 4);
     
     section = section_find_or_make (".text");
@@ -162,7 +162,7 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     part = section_part_new (section, of);
     
-    part->content_size = array_to_integer (elks_exec->a_text, 4);
+    part->content_size = array_to_integer (elks_exec->a_text, 4, 0);
     part->content = xmalloc (part->content_size);
     
     if ((pos - data + part->content_size > data_size) || pos < data) {
@@ -183,7 +183,7 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     part = section_part_new (section, of);
     
-    part->content_size = array_to_integer (elks_exec->a_data, 4);
+    part->content_size = array_to_integer (elks_exec->a_data, 4, 0);
     part->content = xmalloc (part->content_size);
     
     if ((pos - data + part->content_size > data_size) || pos < data) {
@@ -205,12 +205,12 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     section->is_bss = 1;
     
     part = section_part_new (section, of);
-    part->content_size = array_to_integer (elks_exec->a_bss, 4);
+    part->content_size = array_to_integer (elks_exec->a_bss, 4, 0);
     
     section_append_section_part (section, part);
     part_p_array[3] = part;
     
-    pos += array_to_integer (elks_exec->a_syms, 4) + array_to_integer (elks_exec->a_trsize, 4) + array_to_integer (elks_exec->a_drsize, 4);
+    pos += array_to_integer (elks_exec->a_syms, 4, 0) + array_to_integer (elks_exec->a_trsize, 4, 0) + array_to_integer (elks_exec->a_drsize, 4, 0);
     
     if ((unsigned long) (pos - data + 4) > data_size || pos < data) {
     
@@ -219,7 +219,7 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    strtab_size = array_to_integer (pos, 4);
+    strtab_size = array_to_integer (pos, 4, 0);
     
     if (strtab_size < 4) {
     
@@ -239,15 +239,15 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos -= array_to_integer (elks_exec->a_syms, 4);
+    pos -= array_to_integer (elks_exec->a_syms, 4, 0);
     
     for (i = 0; i < num_symbols; i++) {
     
         elks_nlist = (struct elks_nlist *) (pos + (i * sizeof (*elks_nlist)));
         symbol = of->symbol_arr + i;
         
-        if (array_to_integer (elks_nlist->n_strx, 4) < strtab_size) {
-            symbol->name = xstrdup (strtab + array_to_integer (elks_nlist->n_strx, 4));
+        if (array_to_integer (elks_nlist->n_strx, 4, 0) < strtab_size) {
+            symbol->name = xstrdup (strtab + array_to_integer (elks_nlist->n_strx, 4, 0));
         } else {
         
             report_at (program_name, 0, REPORT_FATAL_ERROR, "%s: invalid offset into string table", filename);
@@ -255,7 +255,7 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
         
         }
         
-        symbol->value = array_to_integer (elks_nlist->n_value, 4);
+        symbol->value = array_to_integer (elks_nlist->n_value, 4, 0);
         symbol->size = 0;
         symbol->n_type = elks_nlist->n_type;
         
@@ -309,13 +309,13 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
         
             symbol->section_number = 2;
             symbol->part = part_p_array[2];
-            symbol->value -= array_to_integer (elks_exec->a_text, 4);
+            symbol->value -= array_to_integer (elks_exec->a_text, 4, 0);
         
         } else if ((elks_nlist->n_type & N_TYPE) == N_BSS) {
         
             symbol->section_number = 3;
             symbol->part = part_p_array[3];
-            symbol->value -= (array_to_integer (elks_exec->a_text, 4) + array_to_integer (elks_exec->a_data, 4));
+            symbol->value -= (array_to_integer (elks_exec->a_text, 4, 0) + array_to_integer (elks_exec->a_data, 4, 0));
         
         } else {
         
@@ -343,10 +343,10 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos -= (array_to_integer (elks_exec->a_trsize, 4) + array_to_integer (elks_exec->a_drsize, 4));
+    pos -= (array_to_integer (elks_exec->a_trsize, 4, 0) + array_to_integer (elks_exec->a_drsize, 4, 0));
     part = part_p_array[1];
     
-    part->reloc_cnt = array_to_integer (elks_exec->a_trsize, 4) / sizeof (*reloc_info);
+    part->reloc_cnt = array_to_integer (elks_exec->a_trsize, 4, 0) / sizeof (*reloc_info);
     part->reloc_arr = xmalloc (sizeof (*part->reloc_arr) * part->reloc_cnt);
     
     for (i = 0; i < part->reloc_cnt; i++) {
@@ -356,10 +356,10 @@ void read_elks_object (const char *filename, unsigned char *data, unsigned long
     
     }
     
-    pos += array_to_integer (elks_exec->a_trsize, 4);
+    pos += array_to_integer (elks_exec->a_trsize, 4, 0);
     part = part_p_array[2];
     
-    part->reloc_cnt = array_to_integer (elks_exec->a_drsize, 4) / sizeof (*reloc_info);
+    part->reloc_cnt = array_to_integer (elks_exec->a_drsize, 4, 0) / sizeof (*reloc_info);
     part->reloc_arr = xmalloc (sizeof (*part->reloc_arr) * part->reloc_cnt);
     
     for (i = 0; i < part->reloc_cnt; i++) {
@@ -429,7 +429,7 @@ static unsigned char *write_relocs_for_section (unsigned char *pos, struct secti
                 symbol = symbol_find (symbol->name);
             }
             
-            integer_to_array (part->rva - part->section->rva + part->reloc_arr[i].offset, rel.r_address, 4);
+            integer_to_array (part->rva - part->section->rva + part->reloc_arr[i].offset, rel.r_address, 4, 0);
             
             if (!symbol->part || strcmp (symbol->part->section->name, ".text") == 0) {
                 r_symbolnum = N_TEXT;
@@ -445,7 +445,7 @@ static unsigned char *write_relocs_for_section (unsigned char *pos, struct secti
                 r_symbolnum |= (1LU << 27);
             }
             
-            integer_to_array (r_symbolnum | (size_log2 << 25), rel.r_symbolnum, 4);
+            integer_to_array (r_symbolnum | (size_log2 << 25), rel.r_symbolnum, 4, 0);
             
             memcpy (pos, &rel, sizeof (rel));
             pos += sizeof (rel);
@@ -482,7 +482,7 @@ void elks_write (const char *filename) {
     data_section = section_find (".data");
     bss_section  = section_find (".bss");
     
-    integer_to_array (ELKS_MAGIC, exec.a_magic, 4);
+    integer_to_array (ELKS_MAGIC, exec.a_magic, 4, 0);
     
     exec.a_flags = 0x10;
     exec.a_cpu = (state->format == LD_FORMAT_I386_ELKS) ? 0x10 : 0x04;
@@ -518,26 +518,26 @@ void elks_write (const char *filename) {
     
     }
     
-    integer_to_array (text_size, exec.a_text, 4);
-    integer_to_array (data_size, exec.a_data, 4);
+    integer_to_array (text_size, exec.a_text, 4, 0);
+    integer_to_array (data_size, exec.a_data, 4, 0);
     
-    integer_to_array (bss_size, exec.a_bss, 4);
-    integer_to_array (state->entry_point, exec.a_entry, 4);
+    integer_to_array (bss_size, exec.a_bss, 4, 0);
+    integer_to_array (state->entry_point, exec.a_entry, 4, 0);
     
-    integer_to_array (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4), exec.a_total, 4);
+    integer_to_array (array_to_integer (exec.a_text, 4, 0) + array_to_integer (exec.a_data, 4, 0), exec.a_total, 4, 0);
     
     if (text_section) {
-        integer_to_array (section_get_num_relocs (text_section) * sizeof (struct elks_relocation_info), exec.a_trsize, 4);
+        integer_to_array (section_get_num_relocs (text_section) * sizeof (struct elks_relocation_info), exec.a_trsize, 4, 0);
     }
     
     if (data_section) {
-        integer_to_array (section_get_num_relocs (data_section) * sizeof (struct elks_relocation_info), exec.a_drsize, 4);
+        integer_to_array (section_get_num_relocs (data_section) * sizeof (struct elks_relocation_info), exec.a_drsize, 4, 0);
     }
     
     image_size = sizeof (exec);
     
-    image_size += (array_to_integer (exec.a_text, 4) + array_to_integer (exec.a_data, 4));
-    image_size += (array_to_integer (exec.a_trsize, 4) + array_to_integer (exec.a_drsize, 4));
+    image_size += (array_to_integer (exec.a_text, 4, 0) + array_to_integer (exec.a_data, 4, 0));
+    image_size += (array_to_integer (exec.a_trsize, 4, 0) + array_to_integer (exec.a_drsize, 4, 0));
     
     image_size += 4;
     
@@ -551,13 +551,13 @@ void elks_write (const char *filename) {
         section_write (text_section, pos);
     }
     
-    pos += array_to_integer (exec.a_text, 4);
+    pos += array_to_integer (exec.a_text, 4, 0);
     
     if (data_section) {
         section_write (data_section, pos);
     }
     
-    pos += array_to_integer (exec.a_data, 4);
+    pos += array_to_integer (exec.a_data, 4, 0);
     
     if (text_section) {
         pos = write_relocs_for_section (pos, text_section);
@@ -567,7 +567,7 @@ void elks_write (const char *filename) {
         pos = write_relocs_for_section (pos, data_section);
     }
     
-    integer_to_array (4, pos, 4);
+    integer_to_array (4, pos, 4, 0);
     
     if (fwrite (data, image_size, 1, fp) != 1) {
         report_at (program_name, 0, REPORT_ERROR, "failed to write data to '%s'", filename);
diff --git a/ld.c b/ld.c
index 14553446a9a5d04af27decdaa5bf12f76160f8dc..71e5fafd2212bb308b25d19bc477da58ce36afa2 100644 (file)
--- a/ld.c
+++ b/ld.c
@@ -200,7 +200,7 @@ static void read_archive (const char *filename, unsigned char *data) {
     free (name);
     pos += sizeof (*hdr);
     
-    no_symbols = byte_array_to_integer (pos, 4, 1);
+    no_symbols = array_to_integer (pos, 4, 1);
     pos += 4;
     
     offset_name_table = xmalloc (sizeof (*offset_name_table) * no_symbols);
@@ -208,7 +208,7 @@ static void read_archive (const char *filename, unsigned char *data) {
     
     for (i = 0; i < no_symbols; i++) {
     
-        offset_name_table[i].offset = byte_array_to_integer (pos, 4, 1);
+        offset_name_table[i].offset = array_to_integer (pos, 4, 1);
         offset_name_table[i].name = (char *) string_table_pos;
         
         string_table_pos += strlen (offset_name_table[i].name) + 1;
diff --git a/lib.c b/lib.c
index 6eb89ffbc034d3314184106b2cdeb1ec9b8b3c46..a91dc5bc0c404ab574cec3076e0012890f1fc4f7 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -388,49 +388,32 @@ static void use_option (const char *cmd_arg, int idx, const char *optarg) {
 
 }
 
-unsigned long array_to_integer (unsigned char *arr, int size) {
+unsigned long array_to_integer (unsigned char *arr, int size, int big_endian) {
 
     unsigned long value = 0;
     int i;
     
-    for (i = 0; i < size; i++) {
-        value |= (unsigned long) arr[i] << (CHAR_BIT * i);
-    }
-    
-    return value;
-
-}
-
-unsigned long byte_array_to_integer (unsigned char *arr, int size, int big_endian) {
-
     if (big_endian) {
     
-        unsigned long value = 0;
-        int i, j;
+        int j;
         
         for (i = size, j = 0; i > 0; i--, j++) {
             value |= (unsigned long) arr[j] << (CHAR_BIT * (i - 1));
         }
-        
-        return value;
     
-    }
+    } else {
     
-    return array_to_integer (arr, size);
-
-}
-
-void integer_to_array (unsigned long value, unsigned char *dest, int size) {
-
-    int i;
+        for (i = 0; i < size; i++) {
+            value |= (unsigned long) arr[i] << (CHAR_BIT * i);
+        }
     
-    for (i = 0; i < size; i++) {
-        dest[i] = (value >> (CHAR_BIT * i)) & UCHAR_MAX;
     }
+    
+    return value;
 
 }
 
-void integer_to_byte_array (unsigned long value, unsigned char *dest, int size, int big_endian) {
+void integer_to_array (unsigned long value, unsigned char *dest, int size, int big_endian) {
 
     if (big_endian) {
     
diff --git a/lib.h b/lib.h
index 063c4351067f0c9d7e29993673f1efa5c006dbdd..7ee850ec40de4c420282cc52fb71515406657469 100644 (file)
--- a/lib.h
+++ b/lib.h
@@ -19,11 +19,8 @@ struct ld_option {
 #define     LD_OPTION_NO_ARG            0
 #define     LD_OPTION_HAS_ARG           1
 
-unsigned long array_to_integer (unsigned char *arr, int size);
-unsigned long byte_array_to_integer (unsigned char *arr, int size, int big_endian);
-
-void integer_to_array (unsigned long value, unsigned char *dest, int size);
-void integer_to_byte_array (unsigned long value, unsigned char *dest, int size, int big_endian);
+unsigned long array_to_integer (unsigned char *arr, int size, int big_endian);
+void integer_to_array (unsigned long value, unsigned char *dest, int size, int big_endian);
 
 int xstrcasecmp (const char *__s1, const char *__s2);
 
diff --git a/link.c b/link.c
index bd477f6f3433ec684d6063652c498e15f91a24f4..d47a9bfb1920faa7db6d73456b5fc03870cc0cc7 100644 (file)
--- a/link.c
+++ b/link.c
@@ -161,10 +161,10 @@ static unsigned long generate_symbols_table (unsigned long offset) {
                 continue;
             }
             
-            integer_to_array (symbol_get_value_no_base (symbol), part->content + pos, 4);
+            integer_to_array (symbol_get_value_no_base (symbol), part->content + pos, 4, 0);
             pos += 4;
             
-            integer_to_array (offset, part->content + pos, 4);
+            integer_to_array (offset, part->content + pos, 4, 0);
             pos += 4;
             
             offset += strlen (symbol->name) + 1;
@@ -302,35 +302,35 @@ static void reloc_generic (struct section_part *part, struct reloc_entry *rel, s
     
         case 8: {
         
-            result = array_to_integer (part->content + offset, 8);
+            result = array_to_integer (part->content + offset, 8, 0);
             break;
         
         }
         
         case 4: {
         
-            result = array_to_integer (part->content + offset, 4);
+            result = array_to_integer (part->content + offset, 4, 0);
             break;
         
         }
         
         case 3: {
         
-            result = array_to_integer (part->content + offset, 3);
+            result = array_to_integer (part->content + offset, 3, 0);
             break;
         
         }
         
         case 2: {
         
-            result = array_to_integer (part->content + offset, 2);
+            result = array_to_integer (part->content + offset, 2, 0);
             break;
         
         }
         
         case 1: {
         
-            result = array_to_integer (part->content + offset, 1);
+            result = array_to_integer (part->content + offset, 1, 0);
             break;
         
         }
@@ -530,35 +530,35 @@ static void reloc_generic (struct section_part *part, struct reloc_entry *rel, s
     
         case 8: {
         
-            integer_to_array (result, part->content + offset, 8);
+            integer_to_array (result, part->content + offset, 8, 0);
             break;
         
         }
         
         case 4: {
         
-            integer_to_array (result, part->content + offset, 4);
+            integer_to_array (result, part->content + offset, 4, 0);
             break;
         
         }
         
         case 3: {
         
-            integer_to_array (result, part->content + offset, 3);
+            integer_to_array (result, part->content + offset, 3, 0);
             break;
         
         }
         
         case 2: {
         
-            integer_to_array (result, part->content + offset, 2);
+            integer_to_array (result, part->content + offset, 2, 0);
             break;
         
         }
         
         case 1: {
         
-            integer_to_array (result, part->content + offset, 1);
+            integer_to_array (result, part->content + offset, 1, 0);
             break;
         
         }
diff --git a/mz.c b/mz.c
index f60dca8a6578faccf4003467ccea1549abd165eb..66198c9c6e9858a077bd0929cc0503266b3e6c2e 100644 (file)
--- a/mz.c
+++ b/mz.c
@@ -169,10 +169,10 @@ static unsigned char *write_relocs_for_section (unsigned char *pos, struct secti
             
                 addr = part->rva + part->reloc_arr[i].offset;
                 
-                integer_to_array (addr % 65536, pos, 2);
+                integer_to_array (addr % 65536, pos, 2, 0);
                 pos += 2;
                 
-                integer_to_array (addr / 65536, pos, 2);
+                integer_to_array (addr / 65536, pos, 2, 0);
                 pos += 2;
             
             }
diff --git a/omf.c b/omf.c
index 8d8956230d8b1a90c70427a072d56fe9bdf953dd..d8d158c4e9ff00d0603042fab9f9ac698c60b8fb 100644 (file)
--- a/omf.c
+++ b/omf.c
@@ -40,7 +40,7 @@ static void estimate (void *data, unsigned long data_size, const char *filename,
         big_fields = record_type & 1;
         record_type &= ~1;
         
-        record_len = array_to_integer (pos + 1, 2);
+        record_len = array_to_integer (pos + 1, 2, 0);
         
         {
         
@@ -213,7 +213,7 @@ void read_omf_object (const char *filename, unsigned char *data, unsigned long d
         big_fields = record_type & 1;
         record_type &= ~1;
         
-        record_len = array_to_integer (pos + 1, 2);
+        record_len = array_to_integer (pos + 1, 2, 0);
         pos += 3;
         
         if (record_type == RECORD_TYPE_THEADR) {
@@ -286,9 +286,9 @@ void read_omf_object (const char *filename, unsigned char *data, unsigned long d
                 pubdef_name_len = pubdef_name[prefix - 1];
                 
                 if (big_fields) {
-                    public_offset = array_to_integer (pubdef_name + prefix + pubdef_name_len, 4);
+                    public_offset = array_to_integer (pubdef_name + prefix + pubdef_name_len, 4, 0);
                 } else {
-                    public_offset = array_to_integer (pubdef_name + prefix + pubdef_name_len, 2);
+                    public_offset = array_to_integer (pubdef_name + prefix + pubdef_name_len, 2, 0);
                 }
                 
                 symbol = of->symbol_arr + i_pubdefs++;
@@ -334,14 +334,14 @@ void read_omf_object (const char *filename, unsigned char *data, unsigned long d
             
             if (big_fields) {
             
-                segment_len = array_to_integer (pos + 1, 4);
+                segment_len = array_to_integer (pos + 1, 4, 0);
                 
                 segment_name_index = pos[5];
                 class_name_index = pos[6];
             
             } else {
             
-                segment_len = array_to_integer (pos + 1, 2);
+                segment_len = array_to_integer (pos + 1, 2, 0);
                 
                 segment_name_index = pos[3];
                 class_name_index = pos[4];
@@ -568,14 +568,14 @@ void read_omf_object (const char *filename, unsigned char *data, unsigned long d
             
             if (big_fields) {
             
-                offset = array_to_integer (pos + 1, 4);
+                offset = array_to_integer (pos + 1, 4, 0);
                 
                 size = record_len - 6;
                 data_bytes = pos + 5;
             
             } else {
             
-                offset = array_to_integer (pos + 1, 2);
+                offset = array_to_integer (pos + 1, 2, 0);
                 
                 size = record_len - 4;
                 data_bytes = pos + 3;
diff --git a/pe.c b/pe.c
index 579a395eba8e6783a956d6f0604387492a592a7d..bff2767ff130358a9299aec516be4b76eb1546cb 100644 (file)
--- a/pe.c
+++ b/pe.c
@@ -487,10 +487,10 @@ static void generate_base_relocation_block (struct section *reloc_section, struc
     struct section *section;
     struct section_part *part;
     
-    integer_to_array (ALIGN (sizeof (*ibr_hdr_p) + num_relocs * 2, 4), ibr_hdr_p->SizeOfBlock, 4);
+    integer_to_array (ALIGN (sizeof (*ibr_hdr_p) + num_relocs * 2, 4), ibr_hdr_p->SizeOfBlock, 4, 0);
     
     reloc_part = section_part_new (reloc_section, object_file_make (FAKE_LD_FILENAME, 0));
-    reloc_part->content_size = array_to_integer (ibr_hdr_p->SizeOfBlock, 4);
+    reloc_part->content_size = array_to_integer (ibr_hdr_p->SizeOfBlock, 4, 0);
     
     reloc_part->content = xmalloc (reloc_part->content_size);
     reloc_part->content[reloc_part->content_size - 2] = reloc_part->content[reloc_part->content_size - 1] = 0;
@@ -516,14 +516,14 @@ static void generate_base_relocation_block (struct section *reloc_section, struc
                     continue;
                 }
                 
-                if (part->rva + relocs[i].offset < array_to_integer (ibr_hdr_p->RVAOfBlock, 4)) {
+                if (part->rva + relocs[i].offset < array_to_integer (ibr_hdr_p->RVAOfBlock, 4, 0)) {
                     continue;
                 }
                 
-                rel_word  = (part->rva + relocs[i].offset - array_to_integer (ibr_hdr_p->RVAOfBlock, 4)) & 0xfff;
+                rel_word  = (part->rva + relocs[i].offset - array_to_integer (ibr_hdr_p->RVAOfBlock, 4, 0)) & 0xfff;
                 rel_word |= base_relocation_type << 12;
                 
-                integer_to_array (rel_word, write_pos, 2);
+                integer_to_array (rel_word, write_pos, 2, 0);
                 write_pos += 2;
                 
                 if (!--num_relocs) {
@@ -632,21 +632,21 @@ static void write_sections (unsigned char *data) {
         if (characteristics & IMAGE_SCN_CNT_CODE) {
         
             if (!base_of_code) {
-                base_of_code = array_to_integer (hdr->VirtualAddress, 4);
+                base_of_code = array_to_integer (hdr->VirtualAddress, 4, 0);
             }
             
-            size_of_code += array_to_integer (hdr->VirtualSize, 4);
+            size_of_code += array_to_integer (hdr->VirtualSize, 4, 0);
         
         } else if (characteristics & IMAGE_SCN_CNT_INITIALIZED_DATA) {
         
             if (!base_of_data) {
-                base_of_data = array_to_integer (hdr->VirtualAddress, 4);
+                base_of_data = array_to_integer (hdr->VirtualAddress, 4, 0);
             }
             
-            size_of_initialized_data += array_to_integer (hdr->VirtualSize, 4);
+            size_of_initialized_data += array_to_integer (hdr->VirtualSize, 4, 0);
         
         } else if (characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA) {
-            size_of_uninitialized_data += array_to_integer (hdr->VirtualSize, 4);
+            size_of_uninitialized_data += array_to_integer (hdr->VirtualSize, 4, 0);
         }
         
         last_section = section;
@@ -1071,12 +1071,12 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     length += sizeof (g_Data2) + (sizeof (struct data_entry) * 3);
     length += module_name_length + 1;
     
-    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2);
-    integer_to_array (3, data_descriptor.a, 2);
-    integer_to_array (0, data_descriptor.Id, 4);
-    integer_to_array (length, data_descriptor.Length, 4);
-    integer_to_array (8, data_descriptor.b, 4);
-    integer_to_array (0x1000000, data_descriptor.Flags, 4);
+    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2, 0);
+    integer_to_array (3, data_descriptor.a, 2, 0);
+    integer_to_array (0, data_descriptor.Id, 4, 0);
+    integer_to_array (length, data_descriptor.Length, 4, 0);
+    integer_to_array (8, data_descriptor.b, 4, 0);
+    integer_to_array (0x1000000, data_descriptor.Flags, 4, 0);
     
     offset2 += write_data (outfile, &data_descriptor, sizeof (data_descriptor));
     
@@ -1086,9 +1086,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".debug$S");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0x42100040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0x42100040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     
@@ -1098,11 +1098,11 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".idata$2");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (offset3 + length, section_descriptor_long.AOffset, 4);
-    integer_to_array (3, section_descriptor_long.ACount, 4);
-    integer_to_array (0xC0300040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (offset3 + length, section_descriptor_long.AOffset, 4, 0);
+    integer_to_array (3, section_descriptor_long.ACount, 4, 0);
+    integer_to_array (0xC0300040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     
@@ -1112,9 +1112,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".idata$6");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0xC0200040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0xC0200040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     offset2 += write_data (outfile, g_Data0, sizeof (g_Data0));
@@ -1123,21 +1123,21 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     offset2 += write_data (outfile, g_Data1, sizeof (g_Data1));
     offset2 += write_data (outfile, g_Data2, sizeof (g_Data2));
     
-    integer_to_array (12, data_entry.a, 4);
-    integer_to_array (3, data_entry.b, 4);
-    integer_to_array (7, data_entry.c, 2);
+    integer_to_array (12, data_entry.a, 4, 0);
+    integer_to_array (3, data_entry.b, 4, 0);
+    integer_to_array (7, data_entry.c, 2, 0);
     
     offset2 += write_data (outfile, &data_entry, sizeof (data_entry));
     
-    integer_to_array (0, data_entry.a, 4);
-    integer_to_array (4, data_entry.b, 4);
-    integer_to_array (7, data_entry.c, 2);
+    integer_to_array (0, data_entry.a, 4, 0);
+    integer_to_array (4, data_entry.b, 4, 0);
+    integer_to_array (7, data_entry.c, 2, 0);
     
     offset2 += write_data (outfile, &data_entry, sizeof (data_entry));
     
-    integer_to_array (16, data_entry.a, 4);
-    integer_to_array (5, data_entry.b, 4);
-    integer_to_array (7, data_entry.c, 2);
+    integer_to_array (16, data_entry.a, 4, 0);
+    integer_to_array (5, data_entry.b, 4, 0);
+    integer_to_array (7, data_entry.c, 2, 0);
     
     offset2 += write_data (outfile, &data_entry, sizeof (data_entry));
     offset2 += write_data (outfile, module_name, module_name_length + 1);
@@ -1145,54 +1145,54 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, "@comp.id", 8);
     
-    integer_to_array (0xDD520D, section_descriptor_short.b, 4);
-    integer_to_array (0xFFFF, section_descriptor_short.c, 4);
-    integer_to_array (3, section_descriptor_short.type, 2);
+    integer_to_array (0xDD520D, section_descriptor_short.b, 4, 0);
+    integer_to_array (0xFFFF, section_descriptor_short.c, 4, 0);
+    integer_to_array (3, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     offset3 = 4;
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     
-    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4);
-    integer_to_array (2, section_descriptor_short.c, 4);
-    integer_to_array (2, section_descriptor_short.type, 2);
+    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4, 0);
+    integer_to_array (2, section_descriptor_short.c, 4, 0);
+    integer_to_array (2, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, ".idata$2", 8);
     
-    integer_to_array (0xC0000040, section_descriptor_short.b, 4);
-    integer_to_array (2, section_descriptor_short.c, 4);
-    integer_to_array (0x68, section_descriptor_short.type, 2);
+    integer_to_array (0xC0000040, section_descriptor_short.b, 4, 0);
+    integer_to_array (2, section_descriptor_short.c, 4, 0);
+    integer_to_array (0x68, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, ".idata$6", 8);
     
-    integer_to_array (0, section_descriptor_short.b, 4);
-    integer_to_array (3, section_descriptor_short.c, 4);
-    integer_to_array (3, section_descriptor_short.type, 2);
+    integer_to_array (0, section_descriptor_short.b, 4, 0);
+    integer_to_array (3, section_descriptor_short.c, 4, 0);
+    integer_to_array (3, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, ".idata$4", 8);
     
-    integer_to_array (0xC0000040, section_descriptor_short.b, 4);
-    integer_to_array (0, section_descriptor_short.c, 4);
-    integer_to_array (0x68, section_descriptor_short.type, 2);
+    integer_to_array (0xC0000040, section_descriptor_short.b, 4, 0);
+    integer_to_array (0, section_descriptor_short.c, 4, 0);
+    integer_to_array (0x68, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, ".idata$5", 8);
     
-    integer_to_array (0xC0000040, section_descriptor_short.b, 4);
-    integer_to_array (0, section_descriptor_short.c, 4);
-    integer_to_array (0x68, section_descriptor_short.type, 2);
+    integer_to_array (0xC0000040, section_descriptor_short.b, 4, 0);
+    integer_to_array (0, section_descriptor_short.c, 4, 0);
+    integer_to_array (0x68, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
@@ -1201,9 +1201,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
         memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
         offset3 += info->name_length + 1;
         
-        integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4);
-        integer_to_array (0, section_descriptor_short.c, 4);
-        integer_to_array (2, section_descriptor_short.type, 2);
+        integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4, 0);
+        integer_to_array (0, section_descriptor_short.c, 4, 0);
+        integer_to_array (2, section_descriptor_short.type, 2, 0);
         
         offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
@@ -1234,12 +1234,12 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     length += sizeof (g_Data0) + 1 + module_name_length + sizeof (g_Data1);
     length += sizeof (g_Data2);
     
-    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2);
-    integer_to_array (2, data_descriptor.a, 2);
-    integer_to_array (0, data_descriptor.Id, 4);
-    integer_to_array (length, data_descriptor.Length, 4);
-    integer_to_array (2, data_descriptor.b, 4);
-    integer_to_array (0x1000000, data_descriptor.Flags, 4);
+    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2, 0);
+    integer_to_array (2, data_descriptor.a, 2, 0);
+    integer_to_array (0, data_descriptor.Id, 4, 0);
+    integer_to_array (length, data_descriptor.Length, 4, 0);
+    integer_to_array (2, data_descriptor.b, 4, 0);
+    integer_to_array (0x1000000, data_descriptor.Flags, 4, 0);
     
     offset2 += write_data (outfile, &data_descriptor, sizeof (data_descriptor));
     
@@ -1249,9 +1249,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".debug$S");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0x42100040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0x42100040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     
@@ -1261,9 +1261,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".idata$3");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0xC0300040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0xC0300040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     offset2 += write_data (outfile, g_Data0, sizeof (g_Data0));
@@ -1275,18 +1275,18 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, "@comp.id", 8);
     
-    integer_to_array (0xDD520D, section_descriptor_short.b, 4);
-    integer_to_array (0xFFFF, section_descriptor_short.c, 4);
-    integer_to_array (3, section_descriptor_short.type, 2);
+    integer_to_array (0xDD520D, section_descriptor_short.b, 4, 0);
+    integer_to_array (0xFFFF, section_descriptor_short.c, 4, 0);
+    integer_to_array (3, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     offset3 = 4;
     
-    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4);
-    integer_to_array (2, section_descriptor_short.c, 4);
-    integer_to_array (2, section_descriptor_short.type, 2);
+    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4, 0);
+    integer_to_array (2, section_descriptor_short.c, 4, 0);
+    integer_to_array (2, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     length = offset3 + (info_list->next->name_length + 1);
@@ -1315,12 +1315,12 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     length += sizeof (g_Data0) + 1 + module_name_length + sizeof (g_Data1);
     length += pad_length + pad_length;
     
-    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2);
-    integer_to_array (3, data_descriptor.a, 2);
-    integer_to_array (0, data_descriptor.Id, 4);
-    integer_to_array (length, data_descriptor.Length, 4);
-    integer_to_array (2, data_descriptor.b, 4);
-    integer_to_array (0x1000000, data_descriptor.Flags, 4);
+    integer_to_array (IMAGE_FILE_MACHINE_I386, data_descriptor.Architecture, 2, 0);
+    integer_to_array (3, data_descriptor.a, 2, 0);
+    integer_to_array (0, data_descriptor.Id, 4, 0);
+    integer_to_array (length, data_descriptor.Length, 4, 0);
+    integer_to_array (2, data_descriptor.b, 4, 0);
+    integer_to_array (0x1000000, data_descriptor.Flags, 4, 0);
     
     offset2 += write_data (outfile, &data_descriptor, sizeof (data_descriptor));
     
@@ -1330,9 +1330,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".debug$S");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0x42100040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0x42100040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     
@@ -1342,9 +1342,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".idata$5");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0xC0300040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0xC0300040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     
@@ -1354,9 +1354,9 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_long, 0, sizeof (section_descriptor_long));
     strcpy ((char *) section_descriptor_long.SectionName, ".idata$4");
     
-    integer_to_array (length, section_descriptor_long.Length, 4);
-    integer_to_array (offset3, section_descriptor_long.Offset, 4);
-    integer_to_array (0xC0300040, section_descriptor_long.b, 4);
+    integer_to_array (length, section_descriptor_long.Length, 4, 0);
+    integer_to_array (offset3, section_descriptor_long.Offset, 4, 0);
+    integer_to_array (0xC0300040, section_descriptor_long.b, 4, 0);
     
     offset2 += write_data (outfile, &section_descriptor_long, sizeof (section_descriptor_long));
     offset2 += write_data (outfile, g_Data0, sizeof (g_Data0));
@@ -1370,18 +1370,18 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     memcpy ((char *) section_descriptor_short.z.SectionName, "@comp.id", 8);
     
-    integer_to_array (0xDD520D, section_descriptor_short.b, 4);
-    integer_to_array (0xFFFF, section_descriptor_short.c, 4);
-    integer_to_array (3, section_descriptor_short.type, 2);
+    integer_to_array (0xDD520D, section_descriptor_short.b, 4, 0);
+    integer_to_array (0xFFFF, section_descriptor_short.c, 4, 0);
+    integer_to_array (3, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     
     memset (&section_descriptor_short, 0, sizeof (section_descriptor_short));
     offset3 = 4;
     
-    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4);
-    integer_to_array (2, section_descriptor_short.c, 4);
-    integer_to_array (2, section_descriptor_short.type, 2);
+    integer_to_array (offset3, section_descriptor_short.z.x.Offset, 4, 0);
+    integer_to_array (2, section_descriptor_short.c, 4, 0);
+    integer_to_array (2, section_descriptor_short.type, 2, 0);
     
     offset2 += write_data (outfile, &section_descriptor_short, sizeof (section_descriptor_short));
     length = offset3 + (info_list->next->next->name_length + 1);
@@ -1410,10 +1410,10 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
         offset2 += write_file_header (outfile, header_name, bHeaderName, sizeof (import_hdr) + 1 + strlen (export_names[i].name) + 1 + module_name_length + 1, 0);
         memset (&import_hdr, 0, sizeof (import_hdr));
         
-        integer_to_array (0xFFFF, import_hdr.Magic2, 2);
-        integer_to_array (IMAGE_FILE_MACHINE_I386, import_hdr.Machine, 2);
-        integer_to_array (1 + strlen (export_names[i].name) + 1 + module_name_length + 1, import_hdr.SizeOfData, 4);
-        integer_to_array (ordinal_base + i, import_hdr.OrdinalHint, 2);
+        integer_to_array (0xFFFF, import_hdr.Magic2, 2, 0);
+        integer_to_array (IMAGE_FILE_MACHINE_I386, import_hdr.Machine, 2, 0);
+        integer_to_array (1 + strlen (export_names[i].name) + 1 + module_name_length + 1, import_hdr.SizeOfData, 4, 0);
+        integer_to_array (ordinal_base + i, import_hdr.OrdinalHint, 2, 0);
         
         switch (export_names[i].export_type) {
         
@@ -1436,7 +1436,7 @@ static void write_implib (struct export_name *export_names, unsigned long num_na
         
         type |= (kill_at ? IMPORT_NAME_UNDECORATE : IMPORT_NAME_NOPREFIX) << 2;
         
-        integer_to_array (type, import_hdr.Type, 2);
+        integer_to_array (type, import_hdr.Type, 2, 0);
         offset2 += write_data (outfile, &import_hdr, sizeof (import_hdr));
         
         name = xmalloc (1 + strlen (export_names[i].name) + 1);
@@ -1577,14 +1577,14 @@ static void generate_edata (void) {
     ied = (struct pe_export_directory *) part->content;
     memset (ied, 0, sizeof (*ied));
     
-    integer_to_array (name_table_offset, ied->NameRVA, 4);
-    integer_to_array (ordinal_base, ied->OrdinalBase, 4);
-    integer_to_array (num_names, ied->AddressTableEntries, 4);
-    integer_to_array (num_names, ied->NumberOfNamePointers, 4);
-    integer_to_array (sizeof (*ied), ied->ExportAddressTableRVA, 4);
+    integer_to_array (name_table_offset, ied->NameRVA, 4, 0);
+    integer_to_array (ordinal_base, ied->OrdinalBase, 4, 0);
+    integer_to_array (num_names, ied->AddressTableEntries, 4, 0);
+    integer_to_array (num_names, ied->NumberOfNamePointers, 4, 0);
+    integer_to_array (sizeof (*ied), ied->ExportAddressTableRVA, 4, 0);
     
-    integer_to_array (array_to_integer (ied->ExportAddressTableRVA, 4) + num_names * 4, ied->NamePointerRVA, 4);
-    integer_to_array (array_to_integer (ied->NamePointerRVA, 4) + num_names * 4, ied->OrdinalTableRVA, 4);
+    integer_to_array (array_to_integer (ied->ExportAddressTableRVA, 4, 0) + num_names * 4, ied->NamePointerRVA, 4, 0);
+    integer_to_array (array_to_integer (ied->NamePointerRVA, 4, 0) + num_names * 4, ied->OrdinalTableRVA, 4, 0);
     
     for (i = 0; i < 4; i++) {
     
@@ -1616,21 +1616,21 @@ static void generate_edata (void) {
         
         symbol_record_external_symbol (symbol);
         
-        relocs[0].offset = array_to_integer (ied->ExportAddressTableRVA, 4) + 4 * i;
+        relocs[0].offset = array_to_integer (ied->ExportAddressTableRVA, 4, 0) + 4 * i;
         relocs[0].symbol = symbol;
         relocs[0].howto = &reloc_howtos[RELOC_TYPE_32_NO_BASE];
         
         symbol++;
         relocs++;
         
-        relocs[0].offset = array_to_integer (ied->NamePointerRVA, 4) + 4 * i;
+        relocs[0].offset = array_to_integer (ied->NamePointerRVA, 4, 0) + 4 * i;
         relocs[0].symbol = &of->symbol_arr[0];
         relocs[0].howto = &reloc_howtos[RELOC_TYPE_32_NO_BASE];
         
-        integer_to_array (name_table_offset, part->content + relocs[0].offset, 4);
+        integer_to_array (name_table_offset, part->content + relocs[0].offset, 4, 0);
         relocs++;
         
-        integer_to_array (i, part->content + array_to_integer (ied->OrdinalTableRVA, 4) + 2 * i, 4);
+        integer_to_array (i, part->content + array_to_integer (ied->OrdinalTableRVA, 4, 0) + 2 * i, 4, 0);
         
         name = kill_at ? export_names[i].name_no_at : export_names[i].name;
         strcpy ((char *) part->content + name_table_offset, name);
@@ -1673,7 +1673,7 @@ void pe_after_link (void) {
         report_at (program_name, 0, REPORT_INTERNAL_ERROR, ".reloc section could not be found");
     }
     
-    integer_to_array (0, ibr_hdr.RVAOfBlock, 4);
+    integer_to_array (0, ibr_hdr.RVAOfBlock, 4, 0);
     
     for (section = all_sections; section; section = section->next) {
     
@@ -1687,7 +1687,7 @@ void pe_after_link (void) {
                     continue;
                 }
                 
-                if (num_relocs && (part->rva + relocs[i].offset >= array_to_integer (ibr_hdr.RVAOfBlock, 4) + BASE_RELOCATION_PAGE_SIZE || part->rva + relocs[i].offset < array_to_integer (ibr_hdr.RVAOfBlock, 4))) {
+                if (num_relocs && (part->rva + relocs[i].offset >= array_to_integer (ibr_hdr.RVAOfBlock, 4, 0) + BASE_RELOCATION_PAGE_SIZE || part->rva + relocs[i].offset < array_to_integer (ibr_hdr.RVAOfBlock, 4, 0))) {
                 
                     generate_base_relocation_block (reloc_section, &ibr_hdr, num_relocs, saved_section, saved_part, saved_i);
                     num_relocs = 0;
@@ -1696,7 +1696,7 @@ void pe_after_link (void) {
                 
                 if (num_relocs == 0) {
                 
-                    integer_to_array (FLOOR_TO (part->rva + relocs[i].offset, BASE_RELOCATION_PAGE_SIZE), ibr_hdr.RVAOfBlock, 4);
+                    integer_to_array (FLOOR_TO (part->rva + relocs[i].offset, BASE_RELOCATION_PAGE_SIZE), ibr_hdr.RVAOfBlock, 4, 0);
                     
                     saved_section = section;
                     saved_part = part;
@@ -1852,7 +1852,7 @@ void pe_write (const char *filename) {
     write721_to_byte_array (doshdr->e_lfarlc, sizeof (*doshdr));
     write741_to_byte_array (doshdr->e_lfanew, sizeof (*doshdr) + sizeof (dos_stub));
     
-    memcpy ((char *) data + array_to_integer (doshdr->e_lfarlc, 2), dos_stub, sizeof (dos_stub));
+    memcpy ((char *) data + array_to_integer (doshdr->e_lfarlc, 2, 0), dos_stub, sizeof (dos_stub));
     
     
     pehdr->Signature[0] = 'P';
@@ -2187,7 +2187,7 @@ static void import_generate_import (const char *import_name, short ordinal_hint,
     
     part->content = xmalloc (part->content_size = ALIGN (2 + strlen (real_import_name) + 1, 2));
     
-    integer_to_array (ordinal_hint, part->content, 2);
+    integer_to_array (ordinal_hint, part->content, 2, 0);
     strcpy ((char *) part->content + 2, real_import_name);
     
     free (real_import_name);
@@ -2272,11 +2272,11 @@ static void import_generate_head (const char *filename, const char *dll_name) {
     
     import_dt = (struct pe_import_directory_table *) (part->content = xmalloc (part->content_size = sizeof (*import_dt)));
     
-    integer_to_array (0, import_dt->ImportNameTableRVA, 4);
-    integer_to_array (0, import_dt->TimeDateStamp, 4);
-    integer_to_array (0, import_dt->ForwarderChain, 4);
-    integer_to_array (0, import_dt->NameRVA, 4);
-    integer_to_array (0, import_dt->ImportAddressTableRVA, 4);
+    integer_to_array (0, import_dt->ImportNameTableRVA, 4, 0);
+    integer_to_array (0, import_dt->TimeDateStamp, 4, 0);
+    integer_to_array (0, import_dt->ForwarderChain, 4, 0);
+    integer_to_array (0, import_dt->NameRVA, 4, 0);
+    integer_to_array (0, import_dt->ImportAddressTableRVA, 4, 0);
     
     part->reloc_cnt = 3;
     part->reloc_arr = xmalloc (part->reloc_cnt * sizeof (*part->reloc_arr));
@@ -2383,9 +2383,9 @@ void read_pe_import_library (const char *filename, unsigned char *data) {
         return;
     }
     
-    if ((array_to_integer (import_header->Type, 2) & 0x03) == IMPORT_CONST) {
+    if ((array_to_integer (import_header->Type, 2, 0) & 0x03) == IMPORT_CONST) {
     
-        report_at (__FILE__, __LINE__, REPORT_INTERNAL_ERROR, "+++ not yet supported import header import Type: 0x%x", array_to_integer (import_header->Type, 2) & 0x3);
+        report_at (__FILE__, __LINE__, REPORT_INTERNAL_ERROR, "+++ not yet supported import header import Type: 0x%x", array_to_integer (import_header->Type, 2, 0) & 0x3);
         return;
     
     }
@@ -2409,6 +2409,6 @@ void read_pe_import_library (const char *filename, unsigned char *data) {
     
     }
     
-    import_generate_import (import_name, array_to_integer (import_header->OrdinalHint, 2), array_to_integer (import_header->Type, 2) & 0x03, array_to_integer (import_header->Type, 2) >> 2, filename);
+    import_generate_import (import_name, array_to_integer (import_header->OrdinalHint, 2, 0), array_to_integer (import_header->Type, 2, 0) & 0x03, array_to_integer (import_header->Type, 2, 0) >> 2, filename);
 
 }