Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 228121
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:39:20+00:00 2026-05-11T19:39:20+00:00

Buffer overrun problems are well known. Thus we were blessed with standard library functions

  • 0

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.)

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:39:20+00:00Added an answer on May 11, 2026 at 7:39 pm

    Assuming that your pStr is null terminated and that uiSize is the number of wchar_t of readable memory at pMem:

    wchar_t* pSubStr = std::search( pMem, pMem + uiSize, pStr, pStr + std::wcslen( pStr ) );
    
    // Optionally, change to the 'conventional' strstr return value
    if( pSubStr == pMem + uiSize)
        pSubStr = 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can there be buffer overflow/overrun vulnerabilities in completely managed asp.net web portal.If yes how
I've got a buffer overrun I absolutely can't see to figure out (in C).
My concern is the definition of buffer overrun . Looks like it only applies
I am using snprintf like this to avoid a buffer overrun: char err_msg[32] =
I have a huge buffer of known size. I need to copy chunks of
When I load iphlpapi.dll with LoadLibrary my stack buffer overrun! How can I solve
buffer functions like GetWindowText(), GetModuleFileName(), SHGetFolderPath() make me angry because you almost always waste
I have some buffer and known size #define BUFFER_SIZE 1024*1024 char buffer[BUFFER_SIZE]; I must
c++ function, strtok() cplusplus.com Will this example suffer from buffer overrun if str is
I know that buffer overruns are one potential hazard to using C-style strings (char

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.