[zeromq-dev] zeromq with protobuf segmentation fault while parsing in c++

André Caron andre.l.caron at gmail.com
Tue Jul 1 21:37:18 CEST 2014


Hi Nayab,

This snippet looks suspect in your example code.  It seems like you are
using an uninitialized pointer:

> *Scan *pb_laser_msg_rcv;  // No allocation.*
*> pb_laser_msg_rcv->ParseFromString(ls_msg_str); // Using pointer here is
undefined behavior.*

Try allocating a "Scan" object using new, or better, using an automatic
variable.

Cheers,

André


On Mon, Jun 30, 2014 at 3:57 AM, Nayab Rasul <rasulnrasul at gmail.com> wrote:

> Hi,
>
> I am using zeromq with protobuf to send/recieve messages but code was
> crashing on receiver end with Segmentation fault (core dumped) error while
> parsing the received data.
>
> Scan is my message, and it has float repeated fields.
>
> *sender.cpp*
>
> *Scan proto_ls_msg;*
> *proto_ls_msg.set_angle_min(0.0);*
> *proto_ls_msg.set_angle_max(180.5);*
> *std::string ls_msg_str;*
> *proto_ls_msg.SerializeToString(&ls_msg_str);*
> *zmq::message_t request (ls_msg_str.size());*
> *memcpy (request.data(), ls_msg_str.c_str(),ls_msg_str.size());*
> *socket.send (request);*
>
> *collector.cpp*
>
> *zmq::message_t recieved;*
> *socket.recv (&recieved);*
> *std::string ls_msg_str((char*)recieved.data(),recieved.size()); *
> *Scan *pb_laser_msg_rcv;*
> *pb_laser_msg_rcv->ParseFromString(ls_msg_str); // <--  Segmentation fault
> here*
>
>
> Is there any example code with zeromq and protobuf using repeated float
> fields.
>
>
> thanks.
>
> _______________________________________________
> zeromq-dev mailing list
> zeromq-dev at lists.zeromq.org
> http://lists.zeromq.org/mailman/listinfo/zeromq-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140701/edde4216/attachment.htm>


More information about the zeromq-dev mailing list