Skip to content

Commit

Permalink
Merge pull request booksbyus#649 from uDude/master
Browse files Browse the repository at this point in the history
3 Changes
  • Loading branch information
hintjens authored Jul 6, 2016
2 parents 2066da7 + 6db92b9 commit 1bd3b81
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions examples/C/zhelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>

#if (!defined (WIN32))
# include <sys/time.h>
#endif
Expand Down Expand Up @@ -53,10 +52,9 @@ s_recv (void *socket) {
int size = zmq_recv (socket, buffer, 255, 0);
if (size == -1)
return NULL;
if (size > 255)
size = 255;
buffer [size] = 0;
return strdup (buffer);
return strndup (buffer, sizeof(buffer) - 1);
// remember that the strdup family of functions use malloc/alloc for space for the new string. It must be manually
// freed when you are done with it. Failure to do so will allow a heap attack.
}

// Convert C string to 0MQ string and send to socket
Expand Down

0 comments on commit 1bd3b81

Please sign in to comment.