Skip to content

Commit ccb1917

Browse files
authored
Merge pull request QB64-Phoenix-Edition#543 from a740g/fix-linux-warnings
Silence Linux C++ compiler warnings
2 parents b6d15f9 + a00defb commit ccb1917

File tree

7 files changed

+87
-205
lines changed

7 files changed

+87
-205
lines changed

internal/c/common.h

+1
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
# include <errno.h>
6767
# include <fcntl.h>
6868
# include <fstream>
69+
# include <inttypes.h>
6970
# include <iostream>
7071
# include <limits.h>
7172
# include <stdint.h>

internal/c/libqb.cpp

+14-78
Original file line numberDiff line numberDiff line change
@@ -1854,46 +1854,6 @@ void GLUT_DISPLAY_REQUEST();
18541854

18551855
extern qbs *WHATISMYIP();
18561856

1857-
// directory access defines
1858-
#define EPERM 1
1859-
#define ENOENT 2
1860-
#define ESRCH 3
1861-
#define EINTR 4
1862-
#define EIO 5
1863-
#define ENXIO 6
1864-
#define E2BIG 7
1865-
#define ENOEXEC 8
1866-
#define EBADF 9
1867-
#define ECHILD 10
1868-
#define EAGAIN 11
1869-
#define ENOMEM 12
1870-
#define EACCES 13
1871-
#define EFAULT 14
1872-
#define EBUSY 16
1873-
#define EEXIST 17
1874-
#define EXDEV 18
1875-
#define ENODEV 19
1876-
#define ENOTDIR 20
1877-
#define EISDIR 21
1878-
#define EINVAL 22
1879-
#define ENFILE 23
1880-
#define EMFILE 24
1881-
#define ENOTTY 25
1882-
#define EFBIG 27
1883-
#define ENOSPC 28
1884-
#define ESPIPE 29
1885-
#define EROFS 30
1886-
#define EMLINK 31
1887-
#define EPIPE 32
1888-
#define EDOM 33
1889-
#define ERANGE 34
1890-
#define EDEADLK 36
1891-
#define ENAMETOOint32 38
1892-
#define ENOLCK 39
1893-
#define ENOSYS 40
1894-
#define ENOTEMPTY 41
1895-
#define EILSEQ 42
1896-
18971857
int32 lprint = 0; // set to 1 during LPRINT operations
18981858
int32 lprint_image = 0;
18991859
double lprint_last = 0; // TIMER(0.001) value at last time LPRINT was used
@@ -3550,7 +3510,7 @@ void convert_text_to_utf16(int32 fonthandle, void *buf, int32 size) {
35503510
unicode16_buf = (uint16 *)malloc(unicode16_buf_size);
35513511
}
35523512
// convert text
3553-
if ((fontflags[fonthandle] & FONT_LOAD_UNICODE) && (fonthandle != NULL)) { // unicode font
3513+
if ((fontflags[fonthandle] & FONT_LOAD_UNICODE) && fonthandle) { // unicode font
35543514
if (size == 1)
35553515
size = 4;
35563516
convert_unicode(32, buf, size, 16, unicode16_buf);
@@ -13192,17 +13152,9 @@ void qbs_input(int32 numvariables, uint8 newline) {
1319213152
c->chr[0] = 0;
1319313153
qbs_set(qbs_input_arguements[argn], qbs_add(qbs_input_arguements[argn], c));
1319413154
if (qbs_input_variabletypes[argn] & ISUNSIGNED) {
13195-
#ifdef QB64_WINDOWS
13196-
sscanf((char *)qbs_input_arguements[argn]->chr, "%I64u", (uint64 *)qbs_input_variableoffsets[argn]);
13197-
#else
13198-
sscanf((char *)qbs_input_arguements[argn]->chr, "%llu", (uint64 *)qbs_input_variableoffsets[argn]);
13199-
#endif
13155+
sscanf((char *)qbs_input_arguements[argn]->chr, "%" SCNu64, (uint64_t *)qbs_input_variableoffsets[argn]);
1320013156
} else {
13201-
#ifdef QB64_WINDOWS
13202-
sscanf((char *)qbs_input_arguements[argn]->chr, "%I64i", (int64 *)qbs_input_variableoffsets[argn]);
13203-
#else
13204-
sscanf((char *)qbs_input_arguements[argn]->chr, "%lli", (int64 *)qbs_input_variableoffsets[argn]);
13205-
#endif
13157+
sscanf((char *)qbs_input_arguements[argn]->chr, "%" SCNd64, (int64_t *)qbs_input_variableoffsets[argn]);
1320613158
}
1320713159
goto typechecked;
1320813160
}
@@ -13987,12 +13939,8 @@ finish:;
1398713939
}
1398813940
built_number[i] = 69;
1398913941
i++; // E
13990-
// add exponent
13991-
#ifdef QB64_WINDOWS
13992-
i2 = sprintf((char *)&built_number[i], "%I64i", exponent_value);
13993-
#else
13994-
i2 = sprintf((char *)&built_number[i], "%lli", exponent_value);
13995-
#endif
13942+
// add exponent
13943+
i2 = sprintf((char *)&built_number[i], "%" PRId64, exponent_value);
1399613944
i = i + i2;
1399713945
} else {
1399813946
built_number[i] = 48;
@@ -14986,11 +14934,7 @@ int32 n_float() {
1498614934
}
1498714935
built[i] = 69;
1498814936
i++; // E
14989-
#ifdef QB64_WINDOWS
14990-
i2 = sprintf((char *)&built[i], "%I64i", n_exp);
14991-
#else
14992-
i2 = sprintf((char *)&built[i], "%lli", n_exp);
14993-
#endif
14937+
i2 = sprintf((char *)&built[i], "%" PRId64, n_exp);
1499414938
i = i + i2;
1499514939
built[i] = 0; // NULL terminate for sscanf
1499614940

@@ -18104,7 +18048,7 @@ void sub_bsave(qbs *filename, int32 offset, int32 size) {
1810418048
size &= 0xFFFF;
1810518049
qbs_set(tqbs, qbs_add(filename, nullt)); // prepare null-terminated filename
1810618050
fh.open(filepath_fix_directory(tqbs), std::ios::binary | std::ios::out);
18107-
if (fh.is_open() == NULL) {
18051+
if (!fh.is_open()) {
1810818052
error(64);
1810918053
return;
1811018054
} // Bad file name
@@ -18145,7 +18089,7 @@ void sub_bload(qbs *filename, int32 offset, int32 passed) {
1814518089
}
1814618090
qbs_set(tqbs, qbs_add(filename, nullt)); // prepare null-terminated filename
1814718091
fh.open(filepath_fix_directory(tqbs), std::ios::binary | std::ios::in);
18148-
if (fh.is_open() == NULL) {
18092+
if (!fh.is_open()) {
1814918093
error(53);
1815018094
return;
1815118095
} // File not found
@@ -21739,11 +21683,7 @@ int32 print_using(qbs *f, int32 s2, qbs *dest, qbs *pu_str) {
2173921683
int32 print_using_integer64(qbs *format, int64 value, int32 start, qbs *output) {
2174021684
if (is_error_pending())
2174121685
return 0;
21742-
#ifdef QB64_WINDOWS
21743-
pu_ndig = sprintf((char *)pu_buf, "% I64i", value);
21744-
#else
21745-
pu_ndig = sprintf((char *)pu_buf, "% lli", value);
21746-
#endif
21686+
pu_ndig = sprintf((char *)pu_buf, "% " PRId64, value);
2174721687
if (pu_buf[0] == 45)
2174821688
pu_neg = 1;
2174921689
else
@@ -21758,11 +21698,7 @@ int32 print_using_integer64(qbs *format, int64 value, int32 start, qbs *output)
2175821698
int32 print_using_uinteger64(qbs *format, uint64 value, int32 start, qbs *output) {
2175921699
if (is_error_pending())
2176021700
return 0;
21761-
#ifdef QB64_WINDOWS
21762-
pu_ndig = sprintf((char *)pu_dig, "%I64u", value);
21763-
#else
21764-
pu_ndig = sprintf((char *)pu_dig, "%llu", value);
21765-
#endif
21701+
pu_ndig = sprintf((char *)pu_dig, "%" PRIu64, value);
2176621702
pu_neg = 0;
2176721703
pu_dp = 0;
2176821704
start = print_using(format, start, output, NULL);
@@ -23141,7 +23077,7 @@ void *tcp_host_open(int64 port) {
2314123077
int sockfd;
2314223078
char str_port[6];
2314323079
int yes = 1;
23144-
snprintf(str_port, 6, "%d", port);
23080+
snprintf(str_port, 6, "%" PRId64, port);
2314523081
memset(&hints, 0, sizeof(hints));
2314623082
hints.ai_family = AF_INET;
2314723083
hints.ai_socktype = SOCK_STREAM;
@@ -23231,7 +23167,7 @@ void *tcp_client_open(uint8 *host, int64 port) {
2323123167
struct addrinfo hints, *servinfo, *p;
2323223168
int sockfd;
2323323169
char str_port[6];
23234-
snprintf(str_port, 6, "%d", port);
23170+
snprintf(str_port, 6, "%" PRId64, port);
2323523171
memset(&hints, 0, sizeof(hints));
2323623172
hints.ai_family = AF_INET;
2323723173
hints.ai_socktype = SOCK_STREAM;
@@ -23952,13 +23888,13 @@ void sub__allowfullscreen(int32 method, int32 smooth) {
2395223888
fullscreen_allowedmode = method;
2395323889
if (method == 3 || method == 5)
2395423890
fullscreen_allowedmode = -1;
23955-
if (method == 4 || method == NULL)
23891+
if (method == 4 || method == 0)
2395623892
fullscreen_allowedmode = 0;
2395723893

2395823894
fullscreen_allowedsmooth = smooth;
2395923895
if (smooth == 2 || smooth == 4)
2396023896
fullscreen_allowedsmooth = -1;
23961-
if (smooth == 3 || smooth == NULL)
23897+
if (smooth == 3 || smooth == 0)
2396223898
fullscreen_allowedsmooth = 0;
2396323899
}
2396423900

internal/c/libqb/include/image.h

+11-63
Original file line numberDiff line numberDiff line change
@@ -81,85 +81,33 @@ static inline uint32_t image_get_color_delta(const uint8_t r1, const uint8_t g1,
8181

8282
// Working with 32bit colors:
8383
static inline constexpr uint32_t func__rgb32(int32_t r, int32_t g, int32_t b, int32_t a) {
84-
if (r < 0)
85-
r = 0;
86-
if (r > 255)
87-
r = 255;
88-
if (g < 0)
89-
g = 0;
90-
if (g > 255)
91-
g = 255;
92-
if (b < 0)
93-
b = 0;
94-
if (b > 255)
95-
b = 255;
96-
if (a < 0)
97-
a = 0;
98-
if (a > 255)
99-
a = 255;
100-
return (a << 24) + (r << 16) + (g << 8) + b;
84+
return (image_clamp_color_component(a) << 24) | (image_clamp_color_component(r) << 16) | (image_clamp_color_component(g) << 8) |
85+
image_clamp_color_component(b);
10186
}
10287

10388
static inline constexpr uint32_t func__rgb32(int32_t r, int32_t g, int32_t b) {
104-
if (r < 0)
105-
r = 0;
106-
if (r > 255)
107-
r = 255;
108-
if (g < 0)
109-
g = 0;
110-
if (g > 255)
111-
g = 255;
112-
if (b < 0)
113-
b = 0;
114-
if (b > 255)
115-
b = 255;
116-
return (r << 16) + (g << 8) + b | 0xFF000000;
89+
return 0xFF000000u | (image_clamp_color_component(r) << 16) | (image_clamp_color_component(g) << 8) | image_clamp_color_component(b);
11790
}
11891

11992
static inline constexpr uint32_t func__rgb32(int32_t i, int32_t a) {
120-
if (i < 0)
121-
i = 0;
122-
if (i > 255)
123-
i = 255;
124-
if (a < 0)
125-
a = 0;
126-
if (a > 255)
127-
a = 255;
128-
return (a << 24) + (i << 16) + (i << 8) + i;
93+
i = image_clamp_color_component(i);
94+
return (image_clamp_color_component(a) << 24) | (uint32_t(i) << 16) | (uint32_t(i) << 8) | uint32_t(i);
12995
}
13096

13197
static inline constexpr uint32_t func__rgb32(int32_t i) {
132-
if (i < 0)
133-
i = 0;
134-
if (i > 255)
135-
i = 255;
136-
return (i << 16) + (i << 8) + i | 0xFF000000;
98+
i = image_clamp_color_component(i);
99+
return 0xFF000000u | (uint32_t(i) << 16) | (uint32_t(i) << 8) | uint32_t(i);
137100
}
138101

139102
static inline constexpr uint32_t func__rgba32(int32_t r, int32_t g, int32_t b, int32_t a) {
140-
if (r < 0)
141-
r = 0;
142-
if (r > 255)
143-
r = 255;
144-
if (g < 0)
145-
g = 0;
146-
if (g > 255)
147-
g = 255;
148-
if (b < 0)
149-
b = 0;
150-
if (b > 255)
151-
b = 255;
152-
if (a < 0)
153-
a = 0;
154-
if (a > 255)
155-
a = 255;
156-
return (a << 24) + (r << 16) + (g << 8) + b;
103+
return (image_clamp_color_component(a) << 24) | (image_clamp_color_component(r) << 16) | (image_clamp_color_component(g) << 8) |
104+
image_clamp_color_component(b);
157105
}
158106

159107
static inline constexpr int32_t func__alpha32(uint32_t col) { return col >> 24; }
160108

161-
static inline constexpr int32_t func__red32(uint32_t col) { return col >> 16 & 0xFF; }
109+
static inline constexpr int32_t func__red32(uint32_t col) { return (col >> 16) & 0xFF; }
162110

163-
static inline constexpr int32_t func__green32(uint32_t col) { return col >> 8 & 0xFF; }
111+
static inline constexpr int32_t func__green32(uint32_t col) { return (col >> 8) & 0xFF; }
164112

165113
static inline constexpr int32_t func__blue32(uint32_t col) { return col & 0xFF; }

0 commit comments

Comments
 (0)