Skip to content

Commit 58a9bae

Browse files
committed
fix: exclude standard library functions from generated checked headers
1 parent 096461c commit 58a9bae

File tree

2 files changed

+21
-128
lines changed

2 files changed

+21
-128
lines changed

ci/generate_checked_functions.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,27 @@ def generate_checked_headers(header_paths):
268268
for node in ast.ext
269269
if isinstance(node, c_ast.Decl) and isinstance(node.type, c_ast.FuncDecl)
270270
]
271+
# remove std headers functions
272+
functions = [
273+
f
274+
for f in functions
275+
if f.name
276+
not in (
277+
"__mempcpy",
278+
"__stpcpy",
279+
"memmem",
280+
"memmove",
281+
"mempcpy",
282+
"memset",
283+
"strcasestr",
284+
"strcat",
285+
"strchrnul",
286+
"strcmp",
287+
"strlcat",
288+
"strlcpy",
289+
"strlen",
290+
)
291+
]
271292
functions = sorted(functions, key=lambda f: f.name)
272293

273294
return_types = {

core/iwasm/include/wasm_c_api_checked.h

Lines changed: 0 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -130,27 +130,6 @@ __memcmpeq_checked(void *__s1, void *__s2, size_t __n)
130130
return res;
131131
}
132132

133-
static inline Result
134-
__stpcpy_checked(void *__dest, void *__src)
135-
{
136-
Result res;
137-
// Check for null pointer parameter: __dest
138-
if (__dest == NULL) {
139-
res.error_code = -1;
140-
return res;
141-
}
142-
// Check for null pointer parameter: __src
143-
if (__src == NULL) {
144-
res.error_code = -1;
145-
return res;
146-
}
147-
// Execute the original function
148-
__stpcpy(__dest, __src);
149-
// Assign return value and error code
150-
res.error_code = 0;
151-
return res;
152-
}
153-
154133
static inline Result
155134
__stpncpy_checked(void *__dest, void *__src, size_t __n)
156135
{
@@ -430,43 +409,6 @@ memcpy_checked(void *__dest, void *__src, size_t __n)
430409
return res;
431410
}
432411

433-
static inline Result
434-
memmove_checked(void *__dest, void *__src, size_t __n)
435-
{
436-
Result res;
437-
// Check for null pointer parameter: __dest
438-
if (__dest == NULL) {
439-
res.error_code = -1;
440-
return res;
441-
}
442-
// Check for null pointer parameter: __src
443-
if (__src == NULL) {
444-
res.error_code = -1;
445-
return res;
446-
}
447-
// Execute the original function
448-
memmove(__dest, __src, __n);
449-
// Assign return value and error code
450-
res.error_code = 0;
451-
return res;
452-
}
453-
454-
static inline Result
455-
memset_checked(void *__s, int __c, size_t __n)
456-
{
457-
Result res;
458-
// Check for null pointer parameter: __s
459-
if (__s == NULL) {
460-
res.error_code = -1;
461-
return res;
462-
}
463-
// Execute the original function
464-
memset(__s, __c, __n);
465-
// Assign return value and error code
466-
res.error_code = 0;
467-
return res;
468-
}
469-
470412
static inline Result
471413
rindex_checked(void *__s, int __c)
472414
{
@@ -579,27 +521,6 @@ strcasecmp_l_checked(void *__s1, void *__s2, locale_t __loc)
579521
return res;
580522
}
581523

582-
static inline Result
583-
strcat_checked(void *__dest, void *__src)
584-
{
585-
Result res;
586-
// Check for null pointer parameter: __dest
587-
if (__dest == NULL) {
588-
res.error_code = -1;
589-
return res;
590-
}
591-
// Check for null pointer parameter: __src
592-
if (__src == NULL) {
593-
res.error_code = -1;
594-
return res;
595-
}
596-
// Execute the original function
597-
strcat(__dest, __src);
598-
// Assign return value and error code
599-
res.error_code = 0;
600-
return res;
601-
}
602-
603524
static inline Result
604525
strchr_checked(void *__s, int __c)
605526
{
@@ -616,33 +537,6 @@ strchr_checked(void *__s, int __c)
616537
return res;
617538
}
618539

619-
static inline Result
620-
strcmp_checked(void *__s1, void *__s2)
621-
{
622-
Result res;
623-
// Check for null pointer parameter: __s1
624-
if (__s1 == NULL) {
625-
res.error_code = -1;
626-
return res;
627-
}
628-
// Check for null pointer parameter: __s2
629-
if (__s2 == NULL) {
630-
res.error_code = -1;
631-
return res;
632-
}
633-
// Execute the original function
634-
int original_result = strcmp(__s1, __s2);
635-
// Assign return value and error code
636-
if (original_result == 0) {
637-
res.error_code = 0;
638-
res.value.int_value = original_result;
639-
}
640-
else {
641-
res.error_code = -2;
642-
}
643-
return res;
644-
}
645-
646540
static inline Result
647541
strcoll_checked(void *__s1, void *__s2)
648542
{
@@ -805,28 +699,6 @@ strerror_r_checked(int __errnum, void *__buf, size_t __buflen)
805699
return res;
806700
}
807701

808-
static inline Result
809-
strlen_checked(void *__s)
810-
{
811-
Result res;
812-
// Check for null pointer parameter: __s
813-
if (__s == NULL) {
814-
res.error_code = -1;
815-
return res;
816-
}
817-
// Execute the original function
818-
size_t original_result = strlen(__s);
819-
// Assign return value and error code
820-
if (original_result == 0) {
821-
res.error_code = 0;
822-
res.value.size_t_value = original_result;
823-
}
824-
else {
825-
res.error_code = -2;
826-
}
827-
return res;
828-
}
829-
830702
static inline Result
831703
strncasecmp_checked(void *__s1, void *__s2, size_t __n)
832704
{

0 commit comments

Comments
 (0)