Bug 245200 - emulators/emu64 : Fails to build on FreeBSD 12.1-RELEASE-p1 powerpc 32 bit: error: narrowing conversion of '-1' from 'int' to 'char' [-Wnarrowing]
Summary: emulators/emu64 : Fails to build on FreeBSD 12.1-RELEASE-p1 powerpc 32 bit: e...
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: powerpc Any
: --- Affects Only Me
Assignee: Piotr Kubaj
URL:
Keywords:
: 245315 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-03-31 08:24 UTC by canardo
Modified: 2020-04-03 12:18 UTC (History)
5 users (show)

See Also:
felix: maintainer-feedback+


Attachments
allow narrowing conversions (340 bytes, patch)
2020-03-31 08:39 UTC, Felix Palmen
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description canardo 2020-03-31 08:24:23 UTC
Problem found when building emulators/emu64 on FreeBSD 12.1-RELEASE-p1 r354992 GENERIC powerpc 32 bit, running on Apple Powerbook 17".



/usr/ports/emulators/emu64 # make --DBATCH install clean
===>  Building for emu64-5.0.18
cd src/ && ( test -e Makefile || /usr/local/lib/qt5/bin/qmake -o Makefile /usr/ports/emulators/emu64/work/emu64-5.0.18/src/src.pro -spec /usr/local/lib/qt5/mkspecs/freebsd-g++ QMAKE_CC=gcc9 QMAKE_CXX=g++9 QMAKE_LINK_C=gcc9 QMAKE_LINK_C_SHLIB=gcc9 QMAKE_LINK=g++9 QMAKE_LINK_SHLIB=g++9 'QMAKE_CFLAGS=-O2 -pipe  -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -fno-strict-aliasing ' 'QMAKE_CXXFLAGS=-O2 -pipe  -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9  -Wl,-rpath=/usr/local/lib/gcc9 ' 'QMAKE_LFLAGS= -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -L/usr/local/lib/gcc9 ' QMAKE_LIBS= QMAKE_CFLAGS_DEBUG= QMAKE_CFLAGS_RELEASE= QMAKE_CXXFLAGS_DEBUG= QMAKE_CXXFLAGS_RELEASE= PREFIX=/usr/local CONFIG+=release 'CONFIG-=debug separate_debug_info' ) && /usr/bin/make -f Makefile all
g++9 -c -O2 -pipe -fstack-protector-strong -Wl,-rpath=/usr/local/lib/gcc9 -Wl,-rpath=/usr/local/lib/gcc9 -std=gnu++11 -pthread -Wall -W -pthread -fPIC -DVERSION_STRING=\"5.0.18\" -DARCHITECTURE_STRING=\"Unknown\" -DZIP_SUPPORT=true -DDATA_PATH=\"/usr/local\" -D_REENTRANT -D_THREAD_SAFE -DQT_NO_DEBUG -DQT_WIDGETS_LIB -DQT_GUI_LIB -DQT_CORE_LIB -I../../emu64-5.0.18/src -I. -isystem /usr/local/include/SDL2 -isystem /usr/local/include -isystem /usr/local/include/libpng16 -isystem /usr/local/include/libdrm -isystem /usr/local/include/qt5 -isystem /usr/local/include/qt5/QtWidgets -isystem /usr/local/include/qt5/QtGui -isystem /usr/local/include/qt5/QtCore -I. -isystem /usr/local/include/libdrm -I. -isystem /usr/local/include -I/usr/local/lib/qt5/mkspecs/freebsd-g++ -o c64_class.o ../../emu64-5.0.18/src/c64_class.cpp
../../emu64-5.0.18/src/c64_class.cpp: In member function 'void C64Class::StartEmulation()':
../../emu64-5.0.18/src/c64_class.cpp:541:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  541 |     LogText(">> C64Thread wurde gestartet.\n");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../emu64-5.0.18/src/c64_class.cpp:544:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  544 |     LogText(">> SDL Audiostream wurde getartet.\n");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../emu64-5.0.18/src/c64_class.cpp: In function 'int SDLThread(void*)':
../../emu64-5.0.18/src/c64_class.cpp:618:18: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
  618 |     c64->LogText(">> SDLThread Start.\n");
      |                  ^~~~~~~~~~~~~~~~~~~~~~~
.....
.....
.....
.....
../../emu64-5.0.18/src/c64_class.cpp:1577:13: warning: ISO C++ forbids converting a string constant to 'char*' [-Wwrite-strings]
 1577 |     LogText("\tInitGrafik: Vic-Refresh wurde wieder freigegeben.\n");
      |             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../../emu64-5.0.18/src/c64_class.cpp: In member function 'void C64Class::AnalyzeSDLEvent(SDL_Event*)':
../../emu64-5.0.18/src/c64_class.cpp:1760:46: error: narrowing conversion of '-1' from 'int' to 'char' [-Wnarrowing]
 1760 |     static char joy_axis_tbl[5] = {1,1,0,0,-1};
      |                                              ^
*** [c64_class.o] Error code 1

make[2]: stopped in /usr/ports/emulators/emu64/work/.build/src
1 error

make[2]: stopped in /usr/ports/emulators/emu64/work/.build/src
*** [sub-src-all-ordered] Error code 2

make[1]: stopped in /usr/ports/emulators/emu64/work/.build
1 error

make[1]: stopped in /usr/ports/emulators/emu64/work/.build
===> Compilation failed unexpectedly.
Try to set MAKE_JOBS_UNSAFE=yes and rebuild before reporting the failure to
the maintainer.
*** Error code 1

Stop.
make: stopped in /usr/ports/emulators/emu64
Comment 1 Felix Palmen 2020-03-31 08:39:49 UTC
Created attachment 212886 [details]
allow narrowing conversions

This looks like the code assumes char is always signed, I will report a bug upstream. Could you try whether you can build with the attached patch and whether the result works correctly?
Comment 2 Felix Palmen 2020-03-31 08:47:09 UTC
Upstream issue reported at https://github.com/ThKattanek/emu64/issues/191
Comment 3 canardo 2020-03-31 18:09:54 UTC
(In reply to Felix Palmen from comment #1)

I manually patch the Makefile, and build is now successful.
Comment 4 Felix Palmen 2020-03-31 18:53:48 UTC
Thanks, but the interesting question is whether the emulator actually works as expected :) The patch here only tells the compiler to ignore the problem, so maybe the result isn't behaving correctly. If everything works, I'd keep this patch for now until the next release of emu64 -- otherwise I'll try to import upstream patches.
Comment 5 canardo 2020-04-02 14:14:53 UTC
(In reply to Felix Palmen from comment #4)

Unfortunately, I've plenty of things to tweak on my powerpc, including xorg stuff. So, I'll not be able to test emu64 anytime soon.
Anyways, thanks for the fix, and if I see other problems, I'll report them for sure.
Comment 6 Felix Palmen 2020-04-02 16:38:36 UTC
Ok I have no idea how to move forward on this. My upstream bug report was closed stating the bug was fixed by changing this one occurence and a promise to look over the full source. The patch I attached does not solve the problem, but maybe "works around" it -- someone on an architecture where `char` is unsigned would have to confirm. As an alternative, I could add a patch with the upstream correction, but again, someone has to confirm that. I don't have a system with unsigned `char` at hand ...
Comment 7 Justin Hibbits freebsd_committer 2020-04-02 18:27:18 UTC
Careful, that narrowing on powerpc and arm would yield a value of 255.  If it's used as a '< 0' check later, said check will fail.

I've run into this a lot when people set the return value of getopt() to a char, and compare to -1, leading to an infinite loop.
Comment 8 Felix Palmen 2020-04-02 19:10:24 UTC
(In reply to Justin Hibbits from comment #7)
Justin, that's exactly the reason I wouldn't consider my patch a solution (and I'm a bit disappointed upstream closed my bug report so soon). Now I'm waiting for feedback :)
Comment 9 Alexey Dokuchaev freebsd_committer 2020-04-03 07:10:51 UTC
(In reply to Justin Hibbits from comment #7)
> I've run into this a lot when people set the return value of getopt()
> to a char, and compare to -1, leading to an infinite loop.
I've seen that as well and always wondered why people cannot read the manpage to learn that getopt(3) returns an int, not signed char.
Comment 10 Piotr Kubaj freebsd_committer 2020-04-03 12:12:09 UTC
*** Bug 245315 has been marked as a duplicate of this bug. ***
Comment 11 commit-hook freebsd_committer 2020-04-03 12:17:08 UTC
A commit references this bug:

Author: pkubaj
Date: Fri Apr  3 12:15:53 UTC 2020
New revision: 530485
URL: https://svnweb.freebsd.org/changeset/ports/530485

Log:
  emulators/emu64: fix build on PPC and ARM

  char on PPC and ARM is unsigned.

  PR:		245200
  MFH:		2020Q2 (build fix blanket)

Changes:
  head/emulators/emu64/Makefile
  head/emulators/emu64/files/
  head/emulators/emu64/files/patch-src_c64__class.cpp
Comment 12 commit-hook freebsd_committer 2020-04-03 12:18:09 UTC
A commit references this bug:

Author: pkubaj
Date: Fri Apr  3 12:16:54 UTC 2020
New revision: 530486
URL: https://svnweb.freebsd.org/changeset/ports/530486

Log:
  MFH: r530485

  emulators/emu64: fix build on PPC and ARM

  char on PPC and ARM is unsigned.

  PR:		245200
  Approved by:	portmgr (build fix blanket)

Changes:
_U  branches/2020Q2/
  branches/2020Q2/emulators/emu64/Makefile
  branches/2020Q2/emulators/emu64/files/