[poppler] Compiling poppler with clang

Thomas Freitag Thomas.Freitag at kabelmail.de
Sat Aug 25 23:08:37 PDT 2012


Hi all!

To detect the problems sent by Mateusz "j00ru" Jurczyk and Gynvael 
Coldwind I need the address sanitizer from clang, and therefore I 
compiled poppler the first time with clang. Here I got several warnings 
about unclean code, some of them sound funny, some sound serious. I 
would like to categorize them in these points:

1. Useless if statements like
gmem.cc:112:12: warning: comparison of unsigned expression < 0 is always 
false [-Wtautological-compare]
   if (size < 0) {
       ~~~~ ^ ~

2. Unused private fields
In file included from Gfx.cc:74:
../Gfx.h:222:10: warning: private field 'textClipBBox' is not used 
[-Wunused-private-field]
   double textClipBBox[4];       // text clipping bounding box
          ^
1 warning generated.

3. Comparison of distinct pointer types like
FoFiType1.cc:78:28: warning: comparison of distinct pointer types ('char 
**' and 'const char **') uses non-standard composite pointer type 'const 
char *const *'
   if (encoding && encoding != fofiType1StandardEncoding) {
                   ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~

4. Memory alignment problems
CairoOutputDev.cc:1610:29: warning: cast from 'unsigned char *' to 
'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 
to 4 [-Wcast-align]
     uint32_t *source_data = 
(uint32_t*)cairo_image_surface_get_data(source);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

5. vtable pointer will be overwritten
Function.cc:422:10: warning: destination for this 'memcpy' call is a 
pointer to dynamic class 'SampledFunction'; vtable pointer will be 
overwritten [-Wdynamic-class-memaccess]
   memcpy(this, func, sizeof(SampledFunction));
   ~~~~~~ ^
Function.cc:422:10: note: explicitly cast the pointer to silence this 
warning

At least categrory 5. sound serious to me, I would never have copied 
instances of C++ objects in that way, because it depends on the compiler 
and the class if this causes problems on runtime, s. i.e. 
http://weseetips.com/tag/afx_zero_init_object/, and some other projects 
like chromium already repaired that in the usual way, s. 
http://code.google.com/p/chromium/issues/detail?id=92756

What are You thinking about clean up poppler code to avoid these 
warings? I attach the complete stderr log from make.

@Albert: BTW, do You want a patch for every PDF document from Mateusz 
"j00ru" Jurczyk and Gynvael Coldwind, or can I collect them in the way I 
work on them?

Cheers,
Thomas



-------------- next part --------------
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
gmem.cc:112:12: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
  if (size < 0) {
      ~~~~ ^ ~
gmem.cc:167:12: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
  if (size < 0) {
      ~~~~ ^ ~
2 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
FoFiType1.cc:78:28: warning: comparison of distinct pointer types ('char **' and 'const char **') uses non-standard composite pointer type 'const char *const *'
  if (encoding && encoding != fofiType1StandardEncoding) {
                  ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
clang: warning: argument unused during compilation: '-fno-check-new'
FoFiType1C.cc:90:16: warning: comparison of distinct pointer types ('char **' and 'const char **') uses non-standard composite pointer type 'const char *const *'
      encoding != fofiType1StandardEncoding &&
      ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
FoFiType1C.cc:91:16: warning: comparison of distinct pointer types ('char **' and 'const char **') uses non-standard composite pointer type 'const char *const *'
      encoding != fofiType1ExpertEncoding) {
      ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~
FoFiType1C.cc:303:32: warning: comparison of distinct pointer types ('char **' and 'const char **') uses non-standard composite pointer type 'const char *const *'
  if (!newEncoding && encoding == fofiType1StandardEncoding) {
                      ~~~~~~~~ ^  ~~~~~~~~~~~~~~~~~~~~~~~~~
3 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
SplashFTFont.cc:372:27: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
  if (ff->trueType && gid < 0) {
                      ~~~ ^ ~
SplashFTFont.cc:421:27: warning: comparison of unsigned expression < 0 is always false [-Wtautological-compare]
  if (ff->trueType && gid < 0) {
                      ~~~ ^ ~
2 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
Function.cc:422:10: warning: destination for this 'memcpy' call is a pointer to dynamic class 'SampledFunction'; vtable pointer will be overwritten [-Wdynamic-class-memaccess]
  memcpy(this, func, sizeof(SampledFunction));
  ~~~~~~ ^
Function.cc:422:10: note: explicitly cast the pointer to silence this warning
  memcpy(this, func, sizeof(SampledFunction));
         ^
         (void*)
Function.cc:605:10: warning: destination for this 'memcpy' call is a pointer to dynamic class 'ExponentialFunction'; vtable pointer will be overwritten [-Wdynamic-class-memaccess]
  memcpy(this, func, sizeof(ExponentialFunction));
  ~~~~~~ ^
Function.cc:605:10: note: explicitly cast the pointer to silence this warning
  memcpy(this, func, sizeof(ExponentialFunction));
         ^
         (void*)
Function.cc:752:10: warning: destination for this 'memcpy' call is a pointer to dynamic class 'StitchingFunction'; vtable pointer will be overwritten [-Wdynamic-class-memaccess]
  memcpy(this, func, sizeof(StitchingFunction));
  ~~~~~~ ^
Function.cc:752:10: note: explicitly cast the pointer to silence this warning
  memcpy(this, func, sizeof(StitchingFunction));
         ^
         (void*)
Function.cc:1169:10: warning: destination for this 'memcpy' call is a pointer to dynamic class 'PostScriptFunction'; vtable pointer will be overwritten [-Wdynamic-class-memaccess]
  memcpy(this, func, sizeof(PostScriptFunction));
  ~~~~~~ ^
Function.cc:1169:10: note: explicitly cast the pointer to silence this warning
  memcpy(this, func, sizeof(PostScriptFunction));
         ^
         (void*)
4 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from Gfx.cc:74:
../Gfx.h:222:10: warning: private field 'textClipBBox' is not used [-Wunused-private-field]
  double textClipBBox[4];       // text clipping bounding box
         ^
1 warning generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from Hints.cc:15:
../Hints.h:59:7: warning: private field 'objectNumberFirst' is not used [-Wunused-private-field]
  int objectNumberFirst;
      ^
1 warning generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from OptionalContent.cc:26:
../OptionalContent.h:104:9: warning: private field 'xref' is not used [-Wunused-private-field]
  XRef *xref;
        ^
1 warning generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from CairoFontEngine.cc:39:
../CairoFontEngine.h:98:11: warning: private field 'doc' is not used [-Wunused-private-field]
  PDFDoc *doc;
          ^
1 warning generated.
clang: warning: argument unused during compilation: '-fno-check-new'
CairoOutputDev.cc:1610:29: warning: cast from 'unsigned char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
    uint32_t *source_data = (uint32_t*)cairo_image_surface_get_data(source);
                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CairoOutputDev.cc:1769:30: warning: cast from 'unsigned char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
  res = downscale_box_filter((uint32_t *)orig_buffer,
                             ^~~~~~~~~~~~~~~~~~~~~~~
CairoOutputDev.cc:1773:9: warning: cast from 'unsigned char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
                             (uint32_t *)dest_buffer, dest_stride);
                             ^~~~~~~~~~~~~~~~~~~~~~~
CairoOutputDev.cc:2413:12: warning: cast from 'unsigned char *' to 'unsigned int *' increases required alignment from 1 to 4 [-Wcast-align]
    dest = (unsigned int *) (buffer + y * row_stride);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CairoOutputDev.cc:2563:12: warning: cast from 'unsigned char *' to 'unsigned int *' increases required alignment from 1 to 4 [-Wcast-align]
    dest = (unsigned int *) (buffer + y * row_stride);
           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
CairoOutputDev.cc:2783:22: warning: cast from 'unsigned char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
    uint32_t *dest = (uint32_t *) (buffer + y * stride);
                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from CairoOutputDev.cc:64:
../UTF8.h:59:12: warning: unused function 'mapUCS2' [-Wunused-function]
static int mapUCS2(Unicode u, char *buf, int bufSize) {
           ^
7 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from pdftohtml.cc:54:
../HtmlOutputDev.h:36:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma interface
        ^
In file included from pdftohtml.cc:54:
In file included from ./HtmlOutputDev.h:45:
../HtmlFonts.h:43:59: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
   GBool Ok(unsigned int xcol){ return ((xcol<=255)&&(xcol>=0));}
                                                      ~~~~^ ~
2 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
In file included from HtmlFonts.cc:34:
../HtmlFonts.h:43:59: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
   GBool Ok(unsigned int xcol){ return ((xcol<=255)&&(xcol>=0));}
                                                      ~~~~^ ~
HtmlFonts.cc:86:9: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
  if ((k>=0)&&(k<10)) tmp=(char) ('0'+k); else tmp=(char)('a'+k-10);
       ~^ ~
HtmlFonts.cc:89:9: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
  if ((k>=0)&&(k<10)) tmp=(char) ('0'+k); else tmp=(char)('a'+k-10);
       ~^ ~
3 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
HtmlOutputDev.cc:43:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma implementation
        ^
In file included from HtmlOutputDev.cc:64:
../HtmlOutputDev.h:36:9: warning: unknown pragma ignored [-Wunknown-pragmas]
#pragma interface
        ^
In file included from HtmlOutputDev.cc:64:
In file included from ./HtmlOutputDev.h:45:
../HtmlFonts.h:43:59: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
   GBool Ok(unsigned int xcol){ return ((xcol<=255)&&(xcol>=0));}
                                                      ~~~~^ ~
3 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
pdftocairo.cc:317:23: warning: cast from 'unsigned char *' to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4 [-Wcast-align]
    uint32_t *pixel = (uint32_t *) (data + y*stride);
                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
poppler-attachment.cc:123:65: warning: cast from 'GTime *' (aka 'int *') to 'time_t *' (aka 'long *') increases required alignment from 4 to 8 [-Wcast-align]
    _poppler_convert_pdf_date_to_gtime (embFile->createDate (), (time_t *)&attachment->ctime);
                                                                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
poppler-attachment.cc:125:62: warning: cast from 'GTime *' (aka 'int *') to 'time_t *' (aka 'long *') increases required alignment from 4 to 8 [-Wcast-align]
    _poppler_convert_pdf_date_to_gtime (embFile->modDate (), (time_t *)&attachment->mtime);
                                                             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-pthread'
clang: warning: argument unused during compilation: '-pthread'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
poppler-global.cpp:239:22: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
    if (str_len_left >= 0) {
        ~~~~~~~~~~~~ ^  ~
poppler-global.cpp:290:22: warning: comparison of unsigned expression >= 0 is always true [-Wtautological-compare]
    if (ret_len_left >= 0) {
        ~~~~~~~~~~~~ ^  ~
2 warnings generated.
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'
clang: warning: argument unused during compilation: '-fno-check-new'
clang: warning: argument unused during compilation: '-ansi'


More information about the poppler mailing list