Buffer overrun problems are well known. Thus we were blessed with standard library functions such as wcscat_s(). And the kind folks at Microsoft have created similar safe string functions such as as StringCbCat().
But I have a problem where I need to search a bit of memory for a string. The Standard library function:
wcsstr( wchar_t* pMem, wchar_t* pStr )
seems great, but…
Sometimes my memory contains garbage, sometimes strings. And when it is garbage I sometimes run off an allocated memory page, [=Access Violation]. I can write my own function yes. But my question is if there is any “standard” function to do safe string search such as:
"wcsstr_s( wchar_t* pMem, size_t uiSize, wchar_t* pStr )" ?
Thanx
[EDIT]
Thanks and kudos to Charles Bailey for a perfect answer to my question. Thanks to others for their efforts too.
And to those of you who doubted the saneness of my scenario: Yes of course it would be good to not ever have garbage in my memory. But I can imagine several scenarios where this situation could occur. In my particular case it is reverse-engineering, and the memory I am serching is in fact not “my memory”, it belongs to another process which I cannot control.
(One other hypothetical scenario could be a tricky debugging situation where corrupted memory needs to be tracked down.)
Assuming that your
pStris null terminated and thatuiSizeis the number ofwchar_tof readable memory atpMem: