This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 238270 - "Change function parameters" refactoring breaks code in case of varargs
Summary: "Change function parameters" refactoring breaks code in case of varargs
Status: NEW
Alias: None
Product: cnd
Classification: Unclassified
Component: Code Model (show other bugs)
Version: 7.4
Hardware: All All
: P3 normal (vote)
Assignee: Alexander Simon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-12 12:27 UTC by Vladimir Kvashin
Modified: 2016-10-31 10:22 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Vladimir Kvashin 2013-11-12 12:27:11 UTC
I used "Change funtion parameters" to a function that takes variable arguments (like printf does). I inserted a new 1-st parameter.

Function declatation and definition was refactored ok.

But its usages were changed wrong: arguments I passed were lost.

This can be very frustrating since expressions I passed to the function were removed. And the code remains compilable (it better won't!)

Code before refactoing:

//-----------------------------------------------------------

#include <stdio.h> 
#include <stdarg.h>

static int trace_flag = 1;

void trace(const char *format, ...);

void trace(const char *format, ...) {
    if (trace_flag) {
        va_list args;
        va_start(args, format);
        fprintf(stderr, "fs_server[%li]: ", (long) getpid());
        vfprintf(stderr, format, args);
        va_end(args);  
        fflush(stderr);
    }
}

int funct(int cnt, char* p1, char* p2) {
    trace("cnt=%d p1=%s p2=%s\n", cnt, p1, p2);
    return 0;
}

void main() {
    funct(1, "a", "b");
}


Code after refactoing:

//-----------------------------------------------------------

#include <stdio.h> 
#include <stdarg.h>

static int trace_flag = 1;

void trace(int partrace_level, const char *format, ...);

void trace(int partrace_level, const char *format, ...) {
    if (trace_flag) {
        va_list args;
        va_start(args, format);
        fprintf(stderr, "fs_server[%li]: ", (long) getpid());
        vfprintf(stderr, format, args);
        va_end(args);  
        fflush(stderr);
    }
}

int funct(int cnt, char* p1, char* p2) {
    trace(1, "cnt=%d p1=%s p2=%s\n", cnt); // ERROR: p1, p2 are lost
    return 0;
}

void main() {
    funct(1, "a", "b");
}