Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

invalid cruntime parameter _itoa_s

Tags:

c++

winapi

I have experienced a strange behavior when using _itoa_s and _ultoa_s if I try to get a char array from an DWORD. The function returns zero(success) and my application continues, but I'm getting an exception window with error code 0xc0000417 (STATUS_INVALID_CRUNTIME_PARAMETER).

ULONG pid = ProcessHandleToId(hProcess);  
int size = getIntSize(pid);  
char *pidStr = new char[size+1];  
_ultoa_s(pid, pidStr, size+1, 10);  
//do sth with pidStr...
delete[] (pidStr);`   

ProcessHandleToId returns the PID (DWORD) for a given ProcessHandle.

getIntSize returns the number of numbers to the corresponding int/char array (5555 => 4).

like image 420
christian Avatar asked Aug 04 '26 13:08

christian


1 Answers

Yes, the safe CRT functions will abort your program with status code 0xc0000417 when they detect a problem. However, they will do this immediately, the function will not return.

Which means that you are looking at the wrong source code for this problem. It isn't the _ultoa_s() call that's bombing your program. It's another function call, somewhere else in your code. I can't help you find it of course. But the debugger should give you a good idea, look at the call stack when it breaks.

like image 59
Hans Passant Avatar answered Aug 06 '26 04:08

Hans Passant