[Xapian-tickets] [Xapian] #665: Avoid C library functions not guaranteed to be thread-safe

Xapian nobody at xapian.org
Fri Oct 25 23:35:44 BST 2019


#665: Avoid C library functions not guaranteed to be thread-safe
-------------------------+--------------------------
 Reporter:  olly         |             Owner:  olly
     Type:  defect       |            Status:  new
 Priority:  normal       |         Milestone:  1.4.x
Component:  Library API  |           Version:  1.3.2
 Severity:  normal       |        Resolution:
 Keywords:               |        Blocked By:
 Blocking:               |  Operating System:  All
-------------------------+--------------------------

Comment (by olly):

 Actually it seems we can't do this in `<config.h>` because that should be
 included before any other headers, and:

 {{{
 $ cat poison.cc
 #pragma GCC poison atoi
 #include <stdlib.h>
 $ g++ -Wall -W -O2 -c poison.cc
 In file included from /usr/include/c++/9/cstdlib:75,
                  from /usr/include/c++/9/stdlib.h:36,
                  from poison.cc:2:
 /usr/include/stdlib.h:104:12: error: attempt to use poisoned "atoi"
   104 | extern int atoi (const char *__nptr)
       |            ^
 In file included from /usr/include/c++/9/cstdlib:75,
                  from /usr/include/c++/9/stdlib.h:36,
                  from poison.cc:2:
 /usr/include/stdlib.h:361:8: error: attempt to use poisoned "atoi"
   361 | __NTH (atoi (const char *__nptr))
       |        ^
 In file included from /usr/include/c++/9/stdlib.h:36,
                  from poison.cc:2:
 /usr/include/c++/9/cstdlib:91:8: error: attempt to use poisoned "atoi"
    91 | #undef atoi
       |        ^
 /usr/include/c++/9/cstdlib:141:11: error: attempt to use poisoned "atoi"
   141 |   using ::atoi;
       |           ^
 In file included from poison.cc:2:
 /usr/include/c++/9/stdlib.h:56:12: error: attempt to use poisoned "atoi"
    56 | using std::atoi;
       |            ^
 }}}

 So we'd have to poison **after** we include headers which might reference
 the identifier - we can't poison `atoi` and then `#include <stdlib.h>`,
 nor any header which might indirectly `#include <stdlib.h>`.

 Perhaps this is better checked by `xapian-check-patch` - we can easily
 control which directories that applies a check to.

--
Ticket URL: <https://trac.xapian.org/ticket/665#comment:12>
Xapian <https://xapian.org/>
Xapian



More information about the Xapian-tickets mailing list