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 7770177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T16:20:42+00:00 2026-06-01T16:20:42+00:00

I am doing some static analysis work on some old C++ code and my

  • 0

I am doing some static analysis work on some old C++ code and my C++ is not the strongest. I have this piece of code:

void NIDP_clDPLogger::log(TCHAR *logString)
{
    TCHAR temp_logString[1024] = {0};
    _tcsncpy(temp_logString,logString,1024);
    temp_logString[1023] = NULL;
            ...

The static analysis tool is complaining here of indexing logString (the parameter passed in to function) at 1024 when it may be shorter (the size varies, 1024 is the max. size I guess). So I guess my fix is to check the size of logString and use that, like this:

void NIDP_clDPLogger::log(TCHAR *logString)
{

    size_t tempSize = sizeof(logString);
    TCHAR temp_logString[tempSize] = {0};
    _tcsncpy(temp_logString,logString,tempSize);
    temp_logString[tempSize-1] = NULL;

I am just wondering, will this work OK? Can anybody see any flaws/problems? Building and testing this project is slightly difficult so I am basically just looking for a sanity check before I go through all that. Or is there a better way for me to do it? Can I pass a size_t value in to _tcsncpy, because a hardcoded int was there before?

Thanks for all help.

  • 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-06-01T16:20:43+00:00Added an answer on June 1, 2026 at 4:20 pm

    sizeof(logString) will return the size of a TCHAR*, not the size of the array passed as arrays decay to pointers when passed as argument.

    If it is guaranteed that logString is null terminated you could obtain its length using _tcslen(). Otherwise, the only way to know the size of logString is to pass it into the function as another argument.

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

Sidebar

Related Questions

We're doing some code cleanup, fixing signed/unsigned comparisons, running static analysis, etc, on the
while doing some static code analysis I've found a weird one. On a call
I am looking at doing some static code analysis of an exisiting PHP project,
I am just doing a little work this morning making some static libraries. Why
I've been doing some researching and I'm still not 100% certain if this could
I'm working on some custom C++ static code analysis for my PHD thesis. As
Doing some code reviews lately I came across a number of classes that have
Doing some jquery animation. I have certain divs set up with an attribute of
After doing some work with Ruby, Rails, and RSpec last summer and I learned
While doing some JavaScript performance tests I came up with the following piece of

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.