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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:24:23+00:00 2026-05-20T03:24:23+00:00

I have a C SDK I need to use in an iPhone project, and

  • 0

I have a C SDK I need to use in an iPhone project, and the example code was written for use with Visual Studio. It includes use of strcpy_s, which is a Microsoft-only string function.

file_header.header_size = FIT_FILE_HDR_SIZE;
strcpy_s((FIT_UINT8 *)&file_header.data_type, sizeof(".FIT"), ".FIT");  << problem!

I’ve tried changing to strcpy and strncpy like so

strncpy((FIT_UINT8 *)&file_header.data_type, ".FIT", sizeof(".FIT"));

But I get this warning:

warning: pointer targets in passing argument 1 of ‘builtin_strncpy_chk’ differ in signedness

warning: pointer targets in passing argument 1 of ‘__inline_strncpy_chk’ differ in signedness

warning: call to builtin_strncpy_chk will always overflow destination buffer

The struct file_header is this:

typedef struct
{
   FIT_UINT8 header_size; // FIT_FILE_HDR_SIZE (size of this structure)
   FIT_UINT8 protocol_version; // FIT_PROTOCOL_VERSION
   FIT_UINT16 profile_version; // FIT_PROFILE_VERSION
   FIT_UINT32 data_size; // Does not include file header or crc.  Little endian format.
   FIT_UINT8 data_type[4]; // ".FIT"
} FIT_FILE_HDR;

FIT_UINT8 is typedef Unsigned char.

So we can see that it is given an length of 4 in the typedef, and the strcpy_s takes the data_type by reference and copys “.FIT” to it. Where am I going wrong with strncpy? If you haven’t guessed by now I’m not much of a C programmer 🙂

Edit: this does not give me an error, but it is correct?

strncpy((void *)&file_header.data_type, ".FIT", sizeof(file_header.data_type));
  • 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-20T03:24:23+00:00Added an answer on May 20, 2026 at 3:24 am

    With any “safe string” operations, the size should almost always be the size of the destination buffer; if you use the size of the source string, you might as well call memcpy.

    If you want C99 conformance:

    strncpy(file_header.data_type, ".FIT", sizeof file_header.data_type);
    

    However, strlcpy (a BSDism, available in iOS) is preferred by many, because it guarantees that the destination will be nul-terminated:

    strlcpy(file_header.data_type, ".FIT", sizeof file_header.data_type);
    

    Note, however that the nul-terminated string “.FIT” doesn’t actually fit in the allotted space, as it requires 5 characters (1 for the trailing nul). If you use strlcpy, you will see that the resulting string is just “.FI” because strlcpy guarantees nul-termination, and truncates your string if necessary.

    If you require nul-termination then, you probably want to increase the size of the data_type array to 5. As caf correctly points out, this looks like a file header, in which case nul-termination is probably not required; in that case strncpy is preferred; I might even use memcpy, and avoid giving a future developer the idea that the field is a string.

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

Sidebar

Related Questions

Is there a way to use Bluetooth from the iPhone SDK? I have some
I have an Android 2.2 project that I need to use the facebook api
AVFoundation.framework is not where the documentation says it should be. I have iPhone SDK
I have a COM SDK written in C++ and I'd like to create documentation
I have a server process built in Delphi/C++Builder with RemObjects SDK which claims to
Note - I have not delved very deeply into Apple's iPhone SDK yet. However,
After a review of the iPhone SDK documentation, I have not yet found a
In my iPhone application I need to use GPS (CoreLocation to be exact) to
I need to develop a website which will be used exclusively on iPhone and
I have OS 10.6 on my mac. I started with iphone SDK for snow

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.