Closed
Description
I noticed this issue when converting the Icecast code. In the file src/net/sock.c
the function:
int sock_write(sock_t sock, const char *fmt, ...)
is incorrectly converted to:
int sock_write(int sock, const char *fmt : itype(_Ptr<const char> ) )
I created a small example that highlights the issue:
Original C code var_arg.c
:
#include <stdio.h>
#include <stdarg.h>
int fun(int a, ...) {
// define type of variable
va_list L;
int z;
z = 0;
va_start(L, a);
// Loop to adding the int values
for (int i=0; i < a; i++) {
z = z + va_arg(L, int);
}
va_end(L);
return z;
}
int main() {
// Define temporary variables
int x, y, z;
int k;
x = 2;
y = 3;
z = 4;
// calling function
k = fun(3, x, y, z);
// displaying message with result
printf("Total of %d, %d, and %d is %d\n", x, y, z, k);
return 0;
}
checked-c-convert
output:
Note: I added #include <stdio_checked.h>
and #include <stdchecked.h>
before I ran the tool
#include <stdio_checked.h>
#include <stdarg.h>
#include <stdchecked.h>
int fun(int a) {
// define type of variable
va_list L;
int z;
z = 0;
va_start(L, a);
// Loop to adding the int values
for (int i=0; i < a; i++) {
z = z + va_arg(L, int);
}
va_end(L);
return z;
}
int main() {
// Define temporary variables
int x, y, z;
int k;
x = 2;
y = 3;
z = 4;
// calling function
k = fun(3, x, y, z);
// displaying message with result
printf("Total of %d, %d, and %d is %d\n", x, y, z, k);
return 0;
}
The tool deletes the variable argument in fun()
causing an error when using va_start()
Metadata
Metadata
Assignees
Labels
No labels