Bug 268771

Summary: graphics/sane-backends: fix build with clang 15
Product: Ports & Packages Reporter: Dimitry Andric <dim>
Component: Individual Port(s)Assignee: Dimitry Andric <dim>
Status: Closed FIXED    
Severity: Affects Some People CC: fernape, vvd
Priority: --- Flags: vvd: maintainer-feedback+
Version: Latest   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 265425    
Attachments:
Description Flags
graphics/sane-backends: fix build with clang 15 none

Description Dimitry Andric freebsd_committer freebsd_triage 2023-01-05 17:50:32 UTC
During an exp-run for llvm 15 (see bug 265425), it turned out that graphics/sane-backends failed to build with clang 15:

  jpegtopdf.c:204:5: error: incompatible pointer to integer conversion assigning to 'long' from 'char *(int, int)' [-Wint-conversion]
          tz = timezone;
             ^ ~~~~~~~~
  scanimage.c:1248:42: warning: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                png_set_iCCP(*png_ptr, *info_ptr, basename(icc_profile), PNG_COMPRESSION_TYPE_BASE, icc_buffer, icc_size);
                                                  ^
  scanimage.c:1248:42: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'png_const_charp' (aka 'const char *') [-Wint-conversion]
                png_set_iCCP(*png_ptr, *info_ptr, basename(icc_profile), PNG_COMPRESSION_TYPE_BASE, icc_buffer, icc_size);
                                                ^~~~~~~~~~~~~~~~~~~~~

The jpegtopdf error is because 'timezone' as a global external variable does not exist on FreeBSD: it is a glibc-ism. Use struct tm's tm_gmtoff field instead, which also has its sign reversed from the glibc global.

The scanimage error is because basename(3) is used without including <libgen.h>. With glibc, basename() is declared in both string.h and
libgen.h, where the former gives you the GNU specific variant, and the latter the POSIX variant.
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2023-01-05 17:50:53 UTC
Created attachment 239285 [details]
graphics/sane-backends: fix build with clang 15
Comment 2 Vladimir Druzenko freebsd_committer freebsd_triage 2023-01-06 01:18:36 UTC
Comment on attachment 239285 [details]
graphics/sane-backends: fix build with clang 15

Created issue at upstream with this patch: https://gitlab.com/sane-project/backends/-/issues/634
Comment 3 Vladimir Druzenko freebsd_committer freebsd_triage 2023-01-06 01:20:19 UTC
Build fine for me with this patch on 13.1-p5 amd64 with llvm15 - /etc/make.conf:
.if ${.CURDIR:M*/graphics/sane-backends*}
CPP=clang-cpp15
CC=clang15
CXX=clang++15
.endif
Comment 4 Fernando ApesteguĂ­a freebsd_committer freebsd_triage 2023-01-06 10:12:26 UTC
^Triage: reporter is committer, assign accordingly
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-01-06 18:06:02 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=9fbb5958d12c843b3ae52c74a6ecfe5a76623302

commit 9fbb5958d12c843b3ae52c74a6ecfe5a76623302
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2023-01-05 17:04:52 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2023-01-06 18:03:41 +0000

    graphics/sane-backends: fix build with clang 15

    During an exp-run for llvm 15 (see bug 265425), it turned out that
    graphics/sane-backends failed to build with clang 15:

      jpegtopdf.c:204:5: error: incompatible pointer to integer conversion assigning to 'long' from 'char *(int, int)' [-Wint-conversion]
              tz = timezone;
                 ^ ~~~~~~~~
      scanimage.c:1248:42: warning: call to undeclared function 'basename'; ISO C99 and later do not support implicit function declarations [-Wimplicit-function-declaration]
                    png_set_iCCP(*png_ptr, *info_ptr, basename(icc_profile), PNG_COMPRESSION_TYPE_BASE, icc_buffer, icc_size);
                                                      ^
      scanimage.c:1248:42: error: incompatible integer to pointer conversion passing 'int' to parameter of type 'png_const_charp' (aka 'const char *') [-Wint-conversion]
                    png_set_iCCP(*png_ptr, *info_ptr, basename(icc_profile), PNG_COMPRESSION_TYPE_BASE, icc_buffer, icc_size);
                                                    ^~~~~~~~~~~~~~~~~~~~~

    The jpegtopdf error is because 'timezone' as a global external variable
    does not exist on FreeBSD: it is a glibc-ism. Use struct tm's tm_gmtoff
    field instead, which also has its sign reversed from the glibc global.

    The scanimage error is because basename(3) is used without including
    <libgen.h>. With glibc, basename() is declared in both string.h and
    libgen.h, where the former gives you the GNU specific variant, and the
    latter the POSIX variant.

    PR:             268771
    Approved by:    vvd@unislabs.com (maintainer)
    MFH:            2023Q1

 .../sane-backends/files/patch-frontend_jpegtopdf.c (new)   | 14 ++++++++++++++
 .../sane-backends/files/patch-frontend_scanimage.c (new)   | 12 ++++++++++++
 2 files changed, 26 insertions(+)