libmicrohttpd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [libmicrohttpd] Run-Time Check Failure(Static Link in Debug)


From: luozhaotian
Subject: Re: [libmicrohttpd] Run-Time Check Failure(Static Link in Debug)
Date: Wed, 13 Sep 2023 15:58:13 +0800 (CST)

Visual Studio show this Debug Error:

Run-Time Check Failure #1 - A cast to a smaller data type has caused a loss of data.  If this was intentional, you should mask the source of the cast with the appropriate bitmask.  For example: 

       char c = (i & 0xFF);

Changing the code in this way will not affect the quality of the resulting optimized code.

 

After debug, I find the reason is cast to uint8_t.  When cast values bigger than 256 to uint8_t in line 1421-1423,  the Debug Error will be triggered.

 

//mhd_str.c

size_t

MHD_base64_to_bin_n (const char *base64,

                     size_t base64_len,

                     void *bin,

                     size_t bin_size){

     //……

1421      out[j + 0] = (uint8_t) ((((uint8_t) v1) << 2) | (((uint8_t) v2) >> 4));

1422      out[j + 1] = (uint8_t) ((((uint8_t) v2) << 4) | (((uint8_t) v3) >> 2));

1423      out[j + 2] = (uint8_t) ((((uint8_t) v3) << 6) | (((uint8_t) v4)));

   //……

}

 

In Visual Studio, the Debug mode default open /RTC1, but the Release mode doesnt. 

 

As the suggestion by Visual Studio, if we modify the current git master(mhd_str.c) to:
2375      out[j + 0] = (uint8_t) ((((uint8_t) ((((uint8_t) v1) << 2)&0xFF))
                              | ((uint8_t) (((uint8_t) v2) >> 4))) & 0xFF);
2377      out[j + 1] = (uint8_t) ((((uint8_t) ((((uint8_t) v2) << 4) & 0xFF))
                              | ((uint8_t) (((uint8_t) v3) >> 2))) & 0xFF);
2379      out[j + 2] = (uint8_t) ((((uint8_t) ((((uint8_t) v3) << 6)&0xFF))
                              | ((uint8_t) (((uint8_t) v4)))) & 0xFF);

The error didn'tn  appear.

 

Otherwise, if we ignore the error, the program still works.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]