[zeromq-dev] zmq_msg_init_size corrupts data on my system

Wade Hampton wadehamptoniv at gmail.com
Wed May 25 17:45:54 CEST 2016

I have a very simple set of test programs in C as I am learning ZeroMQ
and evaluating it for a project.  My first program set uses zmq_send (PUB)
and zmq_recv (SUB).  This seems to work fine.  My second program set
uses zmq_msg_send and seems to have corrupt data which seems to
happen in the zmq_msg_init_size() function, see snipit below:

  int ii = 0;
  int rc;
  void* ctx = zmq_ctx_new();
  void* pub = zmq_socket(ctx, ZMQ_PUB);

  while(1) {
    zmq_msg_t  msg;
    char my_msg[1024];
    snprintf(my_msg, sizeof(my_msg, "Hello %d", ii++);

    rc = zmq_msg_int_size(&msg, strlen(my_msg));
    memcpy(zmq_msg_data(&msg), my_msg, strlen(my_msg));

    rc = zmq_msg_send(&msg, pub, 0);
    printf("%s\n", my_msg);

The index variable ii gets set to 101 the second time through the loop.

I am new to ZeroMQ (mostly).  I wrote some test programs and looked at it in
2013 but never did anything with it. Yesterday, I re-built and ran the programs
successfully using version 3.x.  Today I updated to version 4.1.4.  Now, my
test programs fail so I created new ones including the above.

The platform is an updated 32-bit CentOS 5.11 desktop (yes, dated but stable).

Could the problem be my old C/C++ 4.1.2 compiler or 32-bit environment?

Any help you can provide would be most appreciated.

Wade Hampton

More information about the zeromq-dev mailing list