xcode - Weird behaviour of C strcpy -


I wrote a small program in C. It's fully compiled and works, when I make it my Makefile and swing , however, this function does not like it in Xcode (or it behaves like this As it should and the chapra is ignoring it).

  size_t getUrlForArgandPlatform char ** dest, const char * arg, const char * platform) {int isLinux = strcmp (forums, "Linux"); Int isOSX = strcmp (forums, "Darwin"); Char * platformUrlDelimiter = malloc (6 + 1); If (isLinux == 0) {strcpy (platformUrlDelimiter, "linux"); } And if (isOSX == 0) {strcpy (platformUrlDelimiter, "osx"); } Other {strcpy (platformUrlDelimiter, "normal"); } Int length = (int) strlen (kBaseUrl); Length + = strollon (platformUrlDelimiter); Length + = stellen (arg); Length + = 5; Four * buffer = (four *) maulok (length); If (buffer == faucet) {exit (EXIT_FAILURE); } Strcpy (buffer, cabage url); Dome (buffer, "/"); Vertical (buffer, platform url, delimiter); Dome (buffer, "/"); Dome (buffer, RGR); Dome (buffer, ".md"); * Dest = Molok (Stellon (buffer) + 1); Streakpy (* dist, buffer); Free (platformUrlDelimiter); Free (buffer); Return Strane (buffer) + 1; }   

This works 4 times out of 10 times. In the other 6 times, Xcode is telling me that it is strcpy (* dest, buffer) code> SIGBRT . If I take a look at the debugger, then I think that the buffer has the same string twice. Why?

The computed size for buffer is not perfect:

  integer = length (int) strlen (kBaseUrl); Length + = strollon (platformUrlDelimiter); Length = = stellen (arg); Length + = 5;   

The last part should be '+6' because you need "md" for 2 times "/" . NUL to finish more .

Comments

Popular posts from this blog

Java - Error: no suitable method found for add(int, java.lang.String) -

java - JPA TypedQuery: Parameter value element did not match expected type -

c++ - static template member variable has internal linkage but is not defined -