Skip to content

convert tool omitting return type ptr when using pthread #623

Closed
@hasantouma

Description

@hasantouma

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 *

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions