xplanet: fix the failing build with clang on NetBSD.

On recent NetBSD with clang, the build of xplanet was failing as
described in PR pkg/54454. This patch taken from FreeBSD fixes the
build. This closes PR pkg/54454. Revbump as the code was changed.
This commit is contained in:
ng0 2019-08-11 15:38:22 +00:00
parent 9dfaa2485b
commit 37d47a8a2f
3 changed files with 94 additions and 3 deletions

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile,v 1.89 2019/08/11 13:25:21 wiz Exp $
# $NetBSD: Makefile,v 1.90 2019/08/11 15:38:22 ng0 Exp $
DISTNAME= xplanet-1.3.0
PKGREVISION= 6
PKGREVISION= 7
CATEGORIES= x11
MASTER_SITES= ${MASTER_SITE_SOURCEFORGE:=xplanet/}

View file

@ -1,4 +1,4 @@
$NetBSD: distinfo,v 1.21 2018/02/13 12:45:02 ryoon Exp $
$NetBSD: distinfo,v 1.22 2019/08/11 15:38:22 ng0 Exp $
SHA1 (xplanet-1.3.0.tar.gz) = 7c5208b501b441a0184cbb334a5658d0309d7dac
RMD160 (xplanet-1.3.0.tar.gz) = b5ba6239019669668aeb7f63391aa850cc3dd8b7
@ -10,4 +10,5 @@ SHA1 (patch-src_libannotate_addSatellites.cpp) = 7c8976a3e88ebac7e4d9b59a38f98f8
SHA1 (patch-src_libimage_gif.c) = 6c107bd1f733fe82f2b88af8ad778e0fe5aea5bd
SHA1 (patch-src_libmultiple_RayleighScattering.cpp) = 3a64033dc0c6915c9cd2eed2e506dd4c802138c9
SHA1 (patch-src_libmultiple_drawStars.cpp) = b6a3f3995f4f1ac77660fdad64524ef6a48c4d50
SHA1 (patch-src_readConfig-fixclang.cpp) = 642e56513e0ae9ebba18ccc653cb089858a18637
SHA1 (patch-src_readConfig.cpp) = c1a46209dfcbb6a37b6c7ff90f633a6450fbd5d9

View file

@ -0,0 +1,90 @@
$NetBSD: patch-src_readConfig-fixclang.cpp,v 1.1 2019/08/11 15:38:22 ng0 Exp $
This patch has been imported from FreeBSD ports, written by adridg.
The later chunks (using i2b) are compile fixes on aarch64 (presumably with
clang6 as well). Typical error message reads
readConfig.cpp:407:54: error: non-constant-expression cannot be narrowed
from type 'int' to 'unsigned char' in initializer list [-Wc++11-narrowing]
unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
^~~~~~~~
readConfig.cpp:407:54: note: insert an explicit cast to silence this issue
unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
^~~~~~~~
static_cast<unsigned char>( )
Since it happens in a half-dozen places, introduce a trivial helper function.
--- src/readConfig.cpp.orig 2018-01-21 16:58:09 UTC
+++ src/readConfig.cpp
@@ -4,6 +4,7 @@
#include <fstream>
#include <sstream>
#include <string>
+#include <clocale>
using namespace std;
#include "body.h"
@@ -20,6 +21,8 @@ using namespace std;
static PlanetProperties *defaultProperties;
static PlanetProperties *currentProperties;
+static inline unsigned char i2b( int x ) { return static_cast<unsigned int>(x) & 0xffU; }
+
static void
readConfig(const char *line, PlanetProperties *planetProperties[])
{
@@ -49,7 +52,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->ArcColor(color);
}
else
@@ -179,7 +182,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->Color(color);
}
else
@@ -244,7 +247,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->GridColor(color);
}
else
@@ -296,7 +299,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->MarkerColor(color);
}
else
@@ -403,7 +406,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->OrbitColor(color);
}
else
@@ -473,7 +476,7 @@ readConfig(const char *line, PlanetPrope
int r, g, b;
if (sscanf(returnString, "%d,%d,%d", &r, &g, &b) == 3)
{
- unsigned char color[3] = { r & 0xff, g & 0xff, b & 0xff };
+ unsigned char color[3] = { i2b(r), i2b(g), i2b(b) };
currentProperties->TextColor(color);
}
else