Skip to content

Commit 3fb2114

Browse files
committed
Merge changes from the higan and bsnes copies of nall.
In general, I chose the higan version if there was a difference, except for the few things I knew had been patched specifically in bsnes: - endian-detection made more portable - fixed a buffer-overflow in string formatting Also, while merging I realised there was a place that used "char *" while most of nall uses "char*", so I fixed that too.
2 parents dc5b2be + e30cb35 commit 3fb2114

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

intrinsics.hpp

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -117,14 +117,6 @@ namespace nall {
117117

118118
}
119119

120-
#if defined(PLATFORM_MACOS)
121-
#include <machine/endian.h>
122-
#elif defined(PLATFORM_LINUX)
123-
#include <endian.h>
124-
#elif defined(PLATFORM_BSD)
125-
#include <sys/endian.h>
126-
#endif
127-
128120
/* Architecture detection */
129121

130122
namespace nall {
@@ -157,12 +149,44 @@ namespace nall {
157149

158150
/* Endian detection */
159151

152+
#if defined(PLATFORM_MACOS)
153+
#include <machine/endian.h>
154+
#elif defined(PLATFORM_LINUX)
155+
#include <endian.h>
156+
#elif defined(PLATFORM_BSD)
157+
#include <sys/endian.h>
158+
#endif
159+
160160
namespace nall {
161161

162-
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) || defined(__LITTLE_ENDIAN__) || defined(__i386__) || defined(__amd64__) || defined(_M_IX86) || defined(_M_AMD64)
162+
// A note on endian constants: Traditional UNIX provides a header that defines
163+
// constants LITTLE_ENDIAN, BIG_ENDIAN, and BYTE_ORDER (set to LITTLE_ENDIAN or
164+
// BIG_ENDIAN as appropriate). However, C89 says that the compiler/libc should
165+
// not introduce any names unless they start with an underscore, so when you're
166+
// compiling in standards-compilant mode, those constants are named
167+
// __LITTLE_ENDIAN, or sometimes _LITTLE_ENDIAN, or sometimes even LITTLE_ENDIAN
168+
// on platforms that care more about tradition than standards. The platforms
169+
// that rename the constants usually provide some other name you can #define to
170+
// say, "forget C89, yes I really want traditional constant names", but *that*
171+
// name also differs from platform to platform, and it affects more than just
172+
// the endian header.
173+
//
174+
// Rather than wade into that mess, let's just test for all the constants we
175+
// know about.
176+
177+
#if (defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) && __BYTE_ORDER == __LITTLE_ENDIAN) \
178+
|| (defined( _BYTE_ORDER) && defined( _LITTLE_ENDIAN) && _BYTE_ORDER == _LITTLE_ENDIAN) \
179+
|| (defined( BYTE_ORDER) && defined( LITTLE_ENDIAN) && BYTE_ORDER == LITTLE_ENDIAN) \
180+
|| defined(__LITTLE_ENDIAN__) \
181+
|| defined(__i386__) || defined(__amd64__) \
182+
|| defined(_M_IX86) || defined(_M_AMD64)
163183
#define ENDIAN_LSB
164184
constexpr auto endian() -> Endian { return Endian::LSB; }
165-
#elif (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) || defined(__BIG_ENDIAN__) || defined(__powerpc__) || defined(_M_PPC)
185+
#elif(defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) && __BYTE_ORDER == __BIG_ENDIAN) \
186+
|| (defined( _BYTE_ORDER) && defined( _BIG_ENDIAN) && _BYTE_ORDER == _BIG_ENDIAN) \
187+
|| (defined( BYTE_ORDER) && defined( BIG_ENDIAN) && BYTE_ORDER == BIG_ENDIAN) \
188+
|| defined(__BIG_ENDIAN__) \
189+
|| defined(__powerpc__) || defined(_M_PPC)
166190
#define ENDIAN_MSB
167191
constexpr auto endian() -> Endian { return Endian::MSB; }
168192
#else

path.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ inline auto userSettings() -> string {
9191
string result = {Path::user(), "Library/Application Support/"};
9292
#else
9393
string result;
94-
if(const char *env = getenv("XDG_CONFIG_HOME")) {
94+
if(const char* env = getenv("XDG_CONFIG_HOME")) {
9595
result = string(env);
9696
} else {
9797
result = {Path::user(), ".config/"};

string/format.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ inline auto string::format(const nall::string_format& params) -> type& {
4141

4242
if(sourceSize > targetSize) {
4343
uint difference = sourceSize - targetSize;
44-
memory::move(&data[x], &data[x + difference], remaining);
44+
memory::move(&data[x], &data[x + difference], remaining - difference);
4545
size -= difference;
4646
} else if(targetSize > sourceSize) {
4747
uint difference = targetSize - sourceSize;

0 commit comments

Comments
 (0)