Note that there are some explanatory texts on larger screens.

plurals
  1. PONeed to replace use of strcpy_s in C code used in iPhone project
    primarykey
    data
    text
    <p>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.</p> <pre><code>file_header.header_size = FIT_FILE_HDR_SIZE; strcpy_s((FIT_UINT8 *)&amp;file_header.data_type, sizeof(".FIT"), ".FIT"); &lt;&lt; problem! </code></pre> <p>I've tried changing to strcpy and strncpy like so</p> <pre><code>strncpy((FIT_UINT8 *)&amp;file_header.data_type, ".FIT", sizeof(".FIT")); </code></pre> <p>But I get this warning: </p> <p>warning: pointer targets in passing argument 1 of '<strong>builtin</strong>_strncpy_chk' differ in signedness</p> <p>warning: pointer targets in passing argument 1 of '__inline_strncpy_chk' differ in signedness</p> <p>warning: call to <strong>builtin</strong>_strncpy_chk will always overflow destination buffer</p> <p>The struct file_header is this:</p> <pre><code>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; </code></pre> <p>FIT_UINT8 is typedef Unsigned char.</p> <p>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 :)</p> <p>Edit: this does not give me an error, but it is correct?</p> <pre><code>strncpy((void *)&amp;file_header.data_type, ".FIT", sizeof(file_header.data_type)); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload