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

converter tool deletes variable arguments #620

Closed
hasantouma opened this issue Jun 19, 2019 · 1 comment
Closed

converter tool deletes variable arguments #620

hasantouma opened this issue Jun 19, 2019 · 1 comment

Comments

@hasantouma
Copy link
Contributor

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()

@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.

@dtarditi dtarditi closed this as completed Sep 2, 2019
sulekhark pushed a commit that referenced this issue Jul 8, 2021
…indows. (#626)

* Fix escaping bugs that currently affect the JSON formatting test on
Windows.

Other escaping bugs may remain; #620 is to fix all of them.

Fixes #619.

* Add test of a backslash in a file path on Linux and Mac OS X.

While I'm here, fix a typo in the name of json_formating.c and add `--`
to its `3c` command lines.
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