Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

examples-code-check.c: Report on missing defined function return types #1429

Merged
merged 1 commit into from
May 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions man/examples-code-check.c
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,15 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
int is_number_func = 0;
int is_inline_func = 0;
int is_struct_func = 0;
int is_ptr = 0;
const char *func_start = NULL;
int is_struct = 0;
unsigned int i;

if (strncmp(buffer, "*void ", sizeof("*void ")-1) == 0) {
if (strncmp(buffer, "*void *", sizeof("*void *")-1) == 0) {
func_start = &buffer[sizeof("*void *")-1];
is_ptr = 1;
} else {
is_void_func = 1;
func_start = &buffer[sizeof("*void ")-1];
Expand All @@ -254,6 +256,7 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
strlen(number_list[i])) == 0) {
if (buffer[1 + strlen(number_list[i])] == '*') {
func_start = &buffer[2 + strlen(number_list[i])];
is_ptr = 1;
} else {
is_number_func = 1;
func_start = &buffer[1 + strlen(number_list[i])];
Expand All @@ -267,6 +270,7 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
strlen(pointer_list[i])) == 0) {
if (buffer[1 + strlen(pointer_list[i])] == '*') {
func_start = &buffer[2 + strlen(pointer_list[i])];
is_ptr = 1;
} else {
is_struct_func = i + 1;
func_start = &buffer[1 + strlen(pointer_list[i])];
Expand Down Expand Up @@ -330,6 +334,19 @@ decode_synopsis_definition(FILE *fpheader, const char *buffer, int in_synopsis)
len = strlen(outbuf);
if (len > 3 && ((outbuf[len-3] == ';' && outbuf[len-2] == '*') ||
(outbuf[len-3] == '*' && outbuf[len-2] == ';'))) {
if (!is_inline_func && !is_void_func && !is_number_func && !is_struct_func && !is_struct &&
!is_ptr) {
char *lcp = strchr(buffer, ' ');

if (lcp)
*lcp = '\000';
fprintf(stderr,
"man/examples-code-check.c: Function return type '%s' undefined in ptr_list[] or number_list[]\n",
&buffer[1]);
if (lcp)
*lcp = ' ';
exit_code = 1;
}
if (is_inline_func) {
strcpy(&outbuf[len-3], ";\n");
}
Expand Down