c-hdr-parser: fix issue for single argument functions

This commit is contained in:
icst 2024-06-29 12:21:38 -04:00
parent c4f47f11e5
commit 0e5dcf57d2

View file

@ -236,6 +236,13 @@ char * parse_c_header_decl_args(int *c, size_t *len, FILE *f) {
(*len)++;
}
s = realloc(s, *len + 1);
s[*len] = ';';
(*len)++;
//fwrite(s, 1, *len, stdout);
//putchar('\n');
return s;
}
@ -324,7 +331,11 @@ char * parse_c_header_sub(char *out, size_t *out_len, const char *sub, size_t su
size_t lwlen = 0;
char * lastword = parse_c_last_word(&lwlen, sub_decl[n]);
assert( lastword != NULL );
//assert( lastword != NULL );
if ( lastword == NULL ) {
lastword = sub_decl[n] + strlen(sub_decl[n]);
lwlen = 0;
}
size_t type_len = (lastword - sub_decl[n]);
size_t type_array_len = ((sub_decl[n] + strlen(sub_decl[n])) - (lastword + lwlen));
@ -343,9 +354,11 @@ char * parse_c_header_sub(char *out, size_t *out_len, const char *sub, size_t su
out[(*out_len)] = ',';
(*out_len)++;
// add identifier
memcpy(out + (*out_len), lastword, lwlen);
(*out_len) += lwlen;
if ( lwlen > 0 ) {
// add identifier
memcpy(out + (*out_len), lastword, lwlen);
(*out_len) += lwlen;
}
out[(*out_len)] = ';';
(*out_len)++;