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

  • SEARCH
  • Home
  • 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 1004849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T08:11:54+00:00 2026-05-16T08:11:54+00:00

WCHAR* someString = LSomeString\n; WCHAR s1[MAX_PATH]; // I’m sure this is right code. StringCchCopyW(s1,

  • 0
WCHAR* someString = L"SomeString\n";
WCHAR s1[MAX_PATH];

// I'm sure this is right code.
StringCchCopyW(s1, _countof(s1), someString);

// But I'm not sure about these example.
StringCchCopyW(s1 + 100, _countof(s1) - 100, someString); // Is it right?
StringCchCopyW(s1 + 100, _countof(s1), someString); // Is it right?

// How about these?
StringCchCatW(s1, _countof(s1) - wcslen(s1), someString); // Is it right?
StringCchCatW(s1, _countof(s1), someString); // Is it right?
  • 1 1 Answer
  • 0 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-16T08:11:54+00:00Added an answer on May 16, 2026 at 8:11 am

    One thing that’s wrong with all of the functions is you’ve neglected to check the return value. Even String Safe functions can fail and if they do they will silently in your code. Return values for string functions should always be checked or you’ve opened yourself to security holes.

    Other than that it’s really hard to answer this with a definitive yes or no because there are subtle issues to consider. Lets take them in order

    StringCchCopyW(s1, _countof(s1), someString);
    

    This is correct and has no real issues other than the ignored return value.

    StringCchCopyW(s1 + 100, _countof(s1) - 100, someString); // Is it right?
    

    It’s hard to answer this one. Following this operation s1+100 will point to a valid string object but this does nothing for s1. It doesn’t open any security holes though.

    StringCchCopyW(s1 + 100, _countof(s1), someString); // Is it right? 
    

    This is very wrong. You’re stating the number of valid characters is MAX_PATH but passing a buffer which has MAX_PATH-100 characters. This can be buffer overflow’d if someString is long enough.

    StringCchCatW(s1, _countof(s1) - wcslen(s1), someString); // Is it right?
    

    This is wrong but not dangerously so. You’re reporting that the length of s1 is actually smaller than it is. It won’t cause an overflows but it will prevent valid strings from being added.

    StringCchCatW(s1, _countof(s1), someString); // Is it right?
    

    This is correct provided that s1 has a valid string in it. If s1 does not have a valid string in it then it can cause the function to incorrectly execute.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In this link unsigned wchar_t is typedef ed as WCHAR . But I cant
I see lot of struct code like below struct codDrives { WCHAR letter; WCHAR
This is an exact duplicate of this question ; however the code linked in
I've been trying to do this simple stuff and Visual studio 2008 does not
This is the relevant code: char c; size_t buffer_size = 0; wchar_t* wc =
Suppose I have this: void func(WCHAR* pythonStatement) { // Do something with pythonStatement }
I have a code that does something like this: char16_t msg[256]={0}; //... wstring wstr;
This is something simple I came up with for this question . I'm not
I am getting an invalid null pointer error from this section of code. I
I have variable WCHAR sDisplayName[1024]; How can I check if sDisplayName contains the string

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.