summaryrefslogtreecommitdiff
path: root/common_modules/module_manager
diff options
context:
space:
mode:
Diffstat (limited to 'common_modules/module_manager')
-rw-r--r--common_modules/module_manager/utilities/module_to_binary.c27
-rw-r--r--common_modules/module_manager/utilities/module_to_c_array.c27
2 files changed, 54 insertions, 0 deletions
diff --git a/common_modules/module_manager/utilities/module_to_binary.c b/common_modules/module_manager/utilities/module_to_binary.c
index bb4f294d..66657fcc 100644
--- a/common_modules/module_manager/utilities/module_to_binary.c
+++ b/common_modules/module_manager/utilities/module_to_binary.c
@@ -9,11 +9,20 @@
/* SPDX-License-Identifier: MIT */
/***************************************************************************/
+// Some portions generated by Claude Code (Opus 5)
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/* MISRA C:2012 Rule 21.3 and Dir 4.12 deviation: dynamic memory is used in this
+ file. This is a host-side conversion utility executed on the development
+ machine, not ThreadX runtime code, and the ELF areas being read have sizes
+ that are only known at run time. Every allocation result is checked for NULL
+ and every buffer is released before its pointer is reused. */
+
+
/* Define the file handles. */
FILE *source_file;
@@ -310,6 +319,20 @@ unsigned char zero_value;
/* Now allocate memory for the code section. */
code_buffer = malloc(code_section_array[i].code_section_size);
+ /* Determine if the memory allocation was successful. */
+ if (code_buffer == NULL)
+ {
+
+ /* Print an error message out. */
+ printf("**** Error: memory allocation failed for code section **** \n");
+
+ /* Close files. */
+ fclose(source_file);
+ fclose(binary_file);
+
+ return(5);
+ }
+
/* Read in the code area. */
j = code_section_array[i].code_section_index;
elf_object_read(section_header[j].elf_section_header_offset, code_buffer, code_section_array[i].code_section_size);
@@ -333,6 +356,10 @@ unsigned char zero_value;
/* Move index into buffer. */
j++;
}
+
+ /* Release the code section buffer before the next section is read. */
+ free(code_buffer);
+ code_buffer = NULL;
}
/* Close files. */
diff --git a/common_modules/module_manager/utilities/module_to_c_array.c b/common_modules/module_manager/utilities/module_to_c_array.c
index d3472416..72461e27 100644
--- a/common_modules/module_manager/utilities/module_to_c_array.c
+++ b/common_modules/module_manager/utilities/module_to_c_array.c
@@ -9,11 +9,20 @@
/* SPDX-License-Identifier: MIT */
/***************************************************************************/
+// Some portions generated by Claude Code (Opus 5)
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+/* MISRA C:2012 Rule 21.3 and Dir 4.12 deviation: dynamic memory is used in this
+ file. This is a host-side conversion utility executed on the development
+ machine, not ThreadX runtime code, and the ELF areas being read have sizes
+ that are only known at run time. Every allocation result is checked for NULL
+ and every buffer is released before its pointer is reused. */
+
+
/* Define the file handles. */
FILE *source_file;
@@ -342,6 +351,20 @@ CODE_SECTION_ENTRY code_section_temp;
/* Now allocate memory for the code section. */
code_buffer = malloc(code_section_array[i].code_section_size);
+ /* Determine if the memory allocation was successful. */
+ if (code_buffer == NULL)
+ {
+
+ /* Print an error message out. */
+ printf("**** Error: memory allocation failed for code section **** \n");
+
+ /* Close files. */
+ fclose(source_file);
+ fclose(array_file);
+
+ return(5);
+ }
+
/* Read in the code area. */
j = code_section_array[i].code_section_index;
elf_object_read(section_header[j].elf_section_header_offset, code_buffer, code_section_array[i].code_section_size);
@@ -390,6 +413,10 @@ CODE_SECTION_ENTRY code_section_temp;
/* Move index into buffer. */
j++;
}
+
+ /* Release the code section buffer before the next section is read. */
+ free(code_buffer);
+ code_buffer = NULL;
}
/* Finally, finish the C array containing the module code. */