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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:43:06+00:00 2026-06-13T08:43:06+00:00

Disclaimer: it’s just another task for beginner so I’m good with the fact that

  • 0

Disclaimer: it’s just another task for beginner so I’m good with the fact that on different compilers and on different architectures I may get different (incompatible) binaries as a result. So it’s ok that it will only work only on this particular machine.

I’m writing and reading size_t from a binary file. Writing looks like:

std::string result;
result.append((char *)&block_size_, sizeof(block_size_));

and soon after that result is written to a file.

But when I read it in a same way:

map_binary.copy((char *)&block_size_, sizeof(block_size_), offset);

I get a warning

warning C4996: 'std::basic_string<_Elem,_Traits,_Alloc>::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\xstring(1777) : see declaration of 'std::basic_string<_Elem,_Traits,_Alloc>::copy'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>,
1>              _Alloc=std::allocator<char>
1>          ]

I cannot get why this code is unsafe and looking for a solution other than pretending there is no issues at all (using the -D_SCL_SECURE_NO_WARNINGS).

So, what am I missing?

PS: right now I’m learning C++ using only standard library, so solutions that use boost or something else are unacceptable.

  • 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-13T08:43:07+00:00Added an answer on June 13, 2026 at 8:43 am

    You’re not missing anything. VC++ is very keen to warn you if you copy anything to a pointer. In this case there is no guarantee that you will get the size of destination correct. After all you might write something like this map_binary.copy((char *)&block_size_, 4, offset); and then find your code fails with a 64-bit compiler.

    If you’re happy with your ability to avoid this kind of error then disable or ignore the warning.

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

Sidebar

Related Questions

Disclaimer: I'm new to unit testing and just getting my feet wet. That being
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Disclaimer : I'm quite a novice to RoR, but not with Ruby (if that
Disclaimer : I kept this because some things may be useful to others, however,
(DISCLAIMER: I'm not a programmer, I spend my time on serverfault, I'm just a
Disclaimer: JS novice I have a JS widget that depends on JQuery. The widget's
Disclaimer, I'm not a PHP programmer, so you might find this question trivial. That's
Disclaimer : this is a strange issue that only happens in a Kindle Fire
Disclaimer: I'm new to most of this I just downloaded virtualbox yesterday and installed
Disclaimer: I'm not actually trying to make one I'm just curious as to how

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.