Skip to content

Using calloc() will keep the pointer wild #8

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 Jul 12, 2019 · 1 comment
Closed

Using calloc() will keep the pointer wild #8

hasantouma opened this issue Jul 12, 2019 · 1 comment
Labels
bug Something isn't working

Comments

@hasantouma
Copy link
Collaborator

hasantouma commented Jul 12, 2019

I came across this issue when converting Icecast in the function thread_create_c() in the src/thread/thread.c file.

When calloc() is used to allocate memory the tool will make the assigned pointer a wild pointer, even if it should be a _Ptr

The following is a small example that illustrates the issue:
bar.c: (with malloc())

#include <stdlib_checked.h>

int main() {

  char *ptr1 = NULL;

  ptr1 = (char *) malloc(sizeof(char));

  return 0;
}

After the conversion, it will produce:
bar.checked.c:

#include <stdlib_checked.h>

int main() {

  _Ptr<char> ptr1 =  NULL;

  ptr1 = (char *) malloc(sizeof(char));

  return 0;
}

Now with calloc()
bar.c: (with calloc())

#include <stdlib_checked.h>

int main() {

  char *ptr1 = NULL;

  ptr1 = (char *) calloc(1, sizeof(char));

  return 0;
}

The porting tool will not make any changes to this file.

Expected output:

#include <stdlib_checked.h>

int main() {

  _Ptr<char> ptr1 =  NULL;

  ptr1 = (char *) calloc(1, sizeof(char));

  return 0;
}
@hasantouma hasantouma added the bug Something isn't working label Jul 12, 2019
Machiry added a commit that referenced this issue Jul 12, 2019
@Machiry
Copy link
Collaborator

Machiry commented Jul 12, 2019

Fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants