Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double to `unsigned long long` causes memory (stack?) corruption

What is wrong with the following code (crashes):

#include <string>
#include <iostream>

void foo(std::string str, unsigned long long val)
{
    std::cout<< str<< " "<< val<< std::endl; // Crashes if commented as well
}

int main()
{
    double d = 30.0;
    foo("abc", d);
}

Visual Studio 2012/ Debug/ Win32

It works in x64 as well as if we change the unsigned long long to long long or even unsigned long

This code snippet crashes. In other scenarios the addresses of the function parameters are changed.

I suspect it has something to do with _stol2 that converts the double to unsigned long long

like image 432
Xyand Avatar asked Nov 12 '22 16:11

Xyand


1 Answers

Submitted to Microsoft as a bug (Accepted)

like image 131
Xyand Avatar answered Nov 15 '22 06:11

Xyand