Thursday, April 28, 2022

[FIXED] Why does va_arg(va_list, type) give me a C6285 warning?

Issue

Everything is working as intended, and I get the values I need from va_arg(va_list, type), but I get this warning everywhere I call va_arg:

Warning C6285 (<non-zero constant> || <non-zero constant>) is always a non-zero constant. Did you intend to use the bitwise-and operator?

Example code:

void Logger::log(LogLevel level, const char* location, uint32_t line, const char* format, ...)
{
    va_list arg_ptr;
    va_start(arg_ptr, format);

    while (*format) {
        // ...
        if (*format == 'd') { // 
            int i = va_arg(arg_ptr, int); // <-- Warning is reported here
            // ...
        }
        // ...
        ++format;
    }
    // ...
    va_end(arg_ptr);
}

Why do I get this warning and how can I get rid of it?

I'm using Visual Studio Community 2019 with Visual C++ 2019


Solution

C6### error codes are IntelliSense codes. These are based on heuristics and are meant to point the attention to potential errors, but can also result in false-positives, which seems to be the case here; it's probably triggering on the va_arg implementation in the CRT:

#define __crt_va_arg(ap, t)                                               \
    ((sizeof(t) > sizeof(__int64) || (sizeof(t) & (sizeof(t) - 1)) != 0) \  // <== Here
        ? **(t**)((ap += sizeof(__int64)) - sizeof(__int64))             \
        :  *(t* )((ap += sizeof(__int64)) - sizeof(__int64)))

I would simply ignore it ...

If it bothers you, report it to the vendor: HelpSend FeedbackReport a Problem...



Answered By - rustyx
Answer Checked By - Senaida (PHPFixing Volunteer)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.