Skip to content

convert tool omitting return type ptr when using pthread #623

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

Closed
hasantouma opened this issue Jun 19, 2019 · 4 comments
Closed

convert tool omitting return type ptr when using pthread #623

hasantouma opened this issue Jun 19, 2019 · 4 comments

Comments

@hasantouma
Copy link
Contributor

I noticed this issue when converting the Icecast code. In the file src/thread/thread.c the function:
static void *_start_routine(void *arg) is incorrectly converted to:
void _start_routine(void *arg : itype(void* ) ) : itype(void* ) ;

I created a small example that highlights the issue:

Original C code ptr_ex.c:

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>

static void *print_message_function( void *ptr );

int main() {
     pthread_t thread;
     char *message = "Thread";
     int  iret;

     iret = pthread_create( &thread, NULL, print_message_function, (void*) message);

     pthread_join(thread, NULL);

     printf("Thread 1 returns: %d\n",iret);

     return 0;
}

static void *print_message_function( void *ptr ) {
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
}

I compiled this code with gcc with no issues:
gcc ptr_ex.c -lpthread

checked-c-convert output:
Note: I added #include <stdio_checked.h> and #include <stdlib_checked.h> before I ran the tool

#include <stdio_checked.h>
#include <stdlib_checked.h>
#include <pthread.h>

void print_message_function(void *ptr : itype(void* ) ) : itype(void* ) ;

int main() {
     pthread_t thread;
     char *message = "Thread";
     int  iret;

     iret = pthread_create( &thread, NULL, print_message_function, (void*) message);

     pthread_join(thread, NULL);

     printf("Thread 1 returns: %d\n",iret);

     return 0;
}

void print_message_function(void *ptr : itype(void* ) ) : itype(void* ) {
     char *message;
     message = (char *) ptr;
     printf("%s \n", message);
}

Note that the return type for print_message_function() is changed from static void * to void, but the CheckedC return type is still itype(void* )

I could only replicate this issue when using pthread_create(). I have observed it in other parts of the Icecast code. Namely when converting src/httpp/httpp.c and src/cfgfile.c. In all cases the itype() has the correct return type, while the C return type omits the *

@hasantouma
Copy link
Contributor Author

I was able to reduce my example to this:

Original C code:

void *print_message_function();

int main() {
     f(print_message_function);
}

void *print_message_function() {
}

checked-c-convert output:

void print_message_function(void) : itype(void* ) ;

int main() {
     f(print_message_function);
}

void print_message_function(void) : itype(void* )  {
}

@dtarditi
Copy link
Member

dtarditi commented Sep 2, 2019

The convert tool has been mostly rewritten. Please reopen if this is still an issue.

@dtarditi dtarditi closed this as completed Sep 2, 2019
@dtarditi
Copy link
Member

dtarditi commented Sep 2, 2019

The convert tool has been mostly rewritten (see PR #642). Please reopen this issue if it still exists.

1 similar comment
@dtarditi
Copy link
Member

dtarditi commented Sep 2, 2019

The convert tool has been mostly rewritten (see PR #642). Please reopen this issue if it still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants