[zeromq-dev] A Warning occurs when compiling application with ZMQ

张杰 charleszhangjie at qq.com
Mon Jun 16 04:47:09 CEST 2014


When I build my application with ZMQ lib (4.0.4) , a warning occurs like that:
  
 /usr/local/lib/libzmq.a(libzmq_la-ipc_listener.o): In function `zmq::ipc_listener_t::set_address(char const*)':
ipc_listener.cpp:(.text+0x58d): warning: the use of `tempnam' is dangerous, better use `mkstemp'
  
 I can find some source code written like that of ipc_listener.cpp :
  
 120 int zmq::ipc_listener_t::set_address (const char *addr_)
121 {
122     //  Create addr on stack for auto-cleanup
123     std::string addr (addr_);
124 
125     //  Allow wildcard file
126     if (addr[0] == '*') {
127         char *tmpstr = tempnam (NULL, NULL);
128         addr.assign (tmpstr);
129         free (tmpstr);
130     }
131 
  
 Here, the use of "tempnam" function will generate a link warning, which seems not graceful though the applicaton works well
  
 I rewrite it using 'mkstemp' rather than 'tempnam', and then make and make install. it looks OK but I don't sure it may cause any damage? 
  
 120 int zmq::ipc_listener_t::set_address (const char *addr_)
121 {
122     //  Create addr on stack for auto-cleanup
123     std::string addr (addr_);
124 
125     //  Allow wildcard file
126     if (addr[0] == '*') {
127         char tmpstr[] = "XXXXXX";
128         int fd = mkstemp(tmpstr);
129         assert(fd!=-1);
130         //char *tmpstr = tempnam (NULL, NULL);
131         addr.assign (tmpstr);
132         unlink(tmpstr);
133         //free (tmpstr);
134     }
135
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20140616/9055f4e9/attachment.htm>


More information about the zeromq-dev mailing list