Skip to content

fix compile warnings in lib/ #6260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion client/Makefile.linux
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,19 @@
# make -f Makefile.linux clean all
# 3) do the same in this dir

OPTS = -O2 -Wall -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough \
-Wno-deprecated-copy \
-Werror=format-security \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \
-D_GLIBCXX_ASSERTIONS \
-fstack-protector -fstack-protector-strong \
-Wl,-z,nodlopen -Wl,-z,noexecstack \
-Wl,-z,relro -Wl,-z,now \
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries

//CC = g++ -O4 -Wall -I ../ -I ../lib/
CC = g++ -g -Wall -I ../ -I ../lib/
//CC = g++ -g -Wall -I ../ -I ../lib/
CC = g++ -g $(OPTS) -I ../ -I ../lib/

PROGS = boinc boinccmd

Expand Down
13 changes: 12 additions & 1 deletion lib/Makefile.linux
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
# make libraries for Linux client and boinccmd

OPTS = -O2 -Wall -Wformat -Wformat=2 -Wconversion -Wimplicit-fallthrough \
-Wno-deprecated-copy \
-Werror=format-security \
-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=3 \
-D_GLIBCXX_ASSERTIONS \
-fstack-clash-protection -fstack-protector-strong \
-Wl,-z,nodlopen -Wl,-z,noexecstack \
-Wl,-z,relro -Wl,-z,now \
-Wl,--as-needed -Wl,--no-copy-dt-needed-entries

//CC = g++ -O4 -Wall -I ../
CC = g++ -g -Wall -I ../
//CC = g++ -g -Wall -I ../
CC = g++ -g $(OPTS) -I ../

all: boinc.a boinc_cmd.a

Expand Down
2 changes: 1 addition & 1 deletion lib/boinc_stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace boinc {
#endif
}

inline int ftell(FILE *f) {
inline long ftell(FILE *f) {
#ifdef _USING_FCGI_
return FCGI_ftell(f);
#else
Expand Down
10 changes: 5 additions & 5 deletions lib/coproc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ void COPROCS::summary_string(char* buf, int len) {
snprintf(buf2, sizeof(buf2),
"[INTEL|%s|%d|%dMB|%s|%d]",
intel_gpu.name, intel_gpu.count,
(int)(intel_gpu.opencl_prop.global_mem_size/MEGA),
(int)((double)intel_gpu.opencl_prop.global_mem_size/MEGA),
intel_gpu.version,
intel_gpu.opencl_prop.opencl_device_version_int
);
Expand All @@ -199,7 +199,7 @@ void COPROCS::summary_string(char* buf, int len) {
snprintf(buf2, sizeof(buf2),
"[apple_gpu|%s|%d|%dMB|%d|%d]",
apple_gpu.model, apple_gpu.count,
(int)(apple_gpu.opencl_prop.global_mem_size/MEGA),
(int)((double)apple_gpu.opencl_prop.global_mem_size/MEGA),
apple_gpu.metal_support,
apple_gpu.opencl_prop.opencl_device_version_int
);
Expand All @@ -219,7 +219,7 @@ void COPROCS::summary_string(char* buf, int len) {
"[opencl_gpu|%s|%d|%dMB|%d]",
cp.type,
cp.count,
(int)(cp.opencl_prop.global_mem_size/MEGA),
(int)((double)cp.opencl_prop.global_mem_size/MEGA),
cp.opencl_prop.opencl_device_version_int
);
strlcat(buf, buf2, len);
Expand Down Expand Up @@ -964,7 +964,7 @@ int COPROC_INTEL::parse(XML_PARSER& xp) {
set_peak_flops();
}
if (!available_ram) {
available_ram = opencl_prop.global_mem_size;
available_ram = (double)opencl_prop.global_mem_size;
}
return 0;
}
Expand Down Expand Up @@ -1072,7 +1072,7 @@ int COPROC_APPLE::parse(XML_PARSER& xp) {
set_peak_flops();
}
if (!available_ram) {
available_ram = opencl_prop.global_mem_size;
available_ram = (double)opencl_prop.global_mem_size;
}
return 0;
}
Expand Down
22 changes: 11 additions & 11 deletions lib/crypt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ int print_raw_data(FILE* f, DATA_BLOCK& x) {
int scan_raw_data(FILE *f, DATA_BLOCK& x) {
int i=0,j;
while(EOF!=(j=fgetc(f))) {
x.data[i]=j;
x.data[i]=(unsigned char)j;
i++;
}
x.len = i;
Expand Down Expand Up @@ -132,7 +132,7 @@ int scan_hex_data(FILE* f, DATA_BLOCK& x) {
int j;
n = fscanf(f, "%2x", &j);
if (n <= 0) break;
x.data[x.len] = j;
x.data[x.len] = (unsigned char)j;
x.len++;
}
#endif
Expand All @@ -159,7 +159,7 @@ static int sscan_hex_data(const char* p, DATA_BLOCK& x) {
);
return ERR_BAD_HEX_FORMAT;
}
x.data[x.len++] = m;
x.data[x.len++] = (unsigned char)m;
nleft--;
p += 2;
}
Expand All @@ -173,7 +173,7 @@ int print_key_hex(FILE* f, KEY* key, int size) {
DATA_BLOCK x;

fprintf(f, "%d\n", key->bits);
len = size - sizeof(key->bits);
len = size - (int)sizeof(key->bits);
x.data = key->data;
x.len = len;
return print_hex_data(f, x);
Expand Down Expand Up @@ -207,14 +207,14 @@ int scan_key_hex(FILE* f, KEY* key, int size) {
#else
int fs = fscanf(f, "%d", &num_bits);
if (fs != 1) return ERR_NULL;
key->bits = num_bits;
len = size - sizeof(key->bits);
key->bits = (unsigned short)num_bits;
len = size - (int)sizeof(key->bits);
for (i=0; i<len; i++) {
// coverity[check_return]
if (fscanf(f, "%2x", &n) != 1) {
return ERR_NULL;
}
key->data[i] = n;
key->data[i] = (unsigned char)n;
}
fs = fscanf(f, ".");
if (fs == EOF) return ERR_NULL;
Expand All @@ -230,15 +230,15 @@ int sscan_key_hex(const char* buf, KEY* key, int size) {

//fprintf(stderr, "buf = %s\n", buf);
n = sscanf(buf, "%d", &num_bits);
key->bits = num_bits; //key->bits is a short
key->bits = (unsigned short)num_bits; //key->bits is a short
//fprintf(stderr, "key->bits = %d\n", key->bits);

if (n != 1) return ERR_XML_PARSE;
buf = strchr(buf, '\n');
if (!buf) return ERR_XML_PARSE;
buf += 1;
db.data = key->data;
db.len = size - sizeof(key->bits); //huh???
db.len = (unsigned)(size - sizeof(key->bits));
retval = sscan_hex_data(buf, db);
return retval;
}
Expand Down Expand Up @@ -479,7 +479,7 @@ void openssl_to_keys(
#endif

memset(&priv, 0, sizeof(priv));
priv.bits = nbits;
priv.bits = (unsigned short)nbits;
#ifdef HAVE_OPAQUE_RSA_DSA_DH
if (n)
bn_to_bin(n, priv.modulus, sizeof(priv.modulus));
Expand Down Expand Up @@ -583,7 +583,7 @@ int openssl_to_private(RSA *from, R_RSA_PRIVATE_KEY *to) {
RSA_get0_factors(from, &p, &q);
RSA_get0_crt_params(from, &dmp1, &dmq1, &iqmp);

to->bits = BN_num_bits(n);
to->bits = (unsigned short)BN_num_bits(n);
if (!_bn2bin(n,to->modulus,MAX_RSA_MODULUS_LEN))
return(0);
if (!_bn2bin(e,to->publicExponent,MAX_RSA_MODULUS_LEN))
Expand Down
2 changes: 1 addition & 1 deletion lib/crypt_prog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ int test_crypt(const std::string& private_keyfile,
strcpy((char*)buf2, test_string.c_str());
DATA_BLOCK in, out;
in.data = buf2;
in.len = test_string.size();
in.len = (unsigned)test_string.size();
out.data = buf;
retval = encrypt_private(private_key, in, out);
if (retval) {
Expand Down
8 changes: 4 additions & 4 deletions lib/diagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -795,20 +795,20 @@ void boinc_catch_signal(int signal) {
size = backtrace (array, 64);
// Anything that calls malloc here (i.e *printf()) will probably fail
// so we'll do it the hard way.
int retval = write(fileno(stderr),"Stack trace (",strlen("Stack trace ("));
ssize_t retval = write(fileno(stderr),"Stack trace (",strlen("Stack trace ("));
char mbuf[10];
char *p=mbuf+9;
int i=size;
int i=(int)size;
*(p--)=0;
while (i) {
*(p--)=i%10+'0';
*(p--)=(char)(i%10+'0');
i/=10;
}
retval = write(fileno(stderr),p+1,strlen(p+1));
retval = write(fileno(stderr)," frames):",strlen(" frames):"));
mbuf[0]=10;
retval = write(fileno(stderr),mbuf,1);
backtrace_symbols_fd(array, size, fileno(stderr));
backtrace_symbols_fd(array, (int)size, fileno(stderr));
if (retval) {}
#endif

Expand Down
8 changes: 4 additions & 4 deletions lib/filesys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ int boinc_copy(const char* orig, const char* newf) {
// under sandbox security, so we copy the file directly.
//
FILE *src, *dst;
int m, n;
size_t m, n;
int retval = 0;
unsigned char buf[65536];
src = boinc_fopen(orig, "r");
Expand All @@ -700,7 +700,7 @@ int boinc_copy(const char* orig, const char* newf) {
}
while (1) {
n = boinc::fread(buf, 1, sizeof(buf), src);
if (n <= 0) {
if (n == 0) {
// could be either EOF or an error.
// Check for error case.
//
Expand Down Expand Up @@ -1111,11 +1111,11 @@ int read_file_malloc(const char* path, char*& buf, size_t max_len, bool tail) {
if (!f) return ERR_FOPEN;

#ifndef _USING_FCGI_
if (max_len && size > max_len) {
if (max_len && size > (double)max_len) {
Copy link
Preview

Copilot AI Apr 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a double conversion for 'max_len' in the size comparison may lead to precision issues; consider using an integer type to ensure consistent behavior.

Suggested change
if (max_len && size > (double)max_len) {
if (max_len && size > max_len) {

Copilot uses AI. Check for mistakes.

if (tail) {
fseek(f, (long)size-(long)max_len, SEEK_SET);
}
size = max_len;
size = (double)max_len;
}
#endif
size_t isize = (size_t)size;
Expand Down
12 changes: 6 additions & 6 deletions lib/gui_rpc_client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,19 @@ int RPC_CLIENT::get_ip_addr(const char* host, int port) {
sin->sin_addr.s_addr = htonl(INADDR_LOOPBACK);
}
if (port) {
port = htons(port);
port = (int)htons((uint16_t)port);
} else {
port = htons(GUI_RPC_PORT);
port = (int)htons(GUI_RPC_PORT);
}
#ifdef _WIN32
addr.sin_port = port;
#else
if (addr.ss_family == AF_INET) {
sockaddr_in* sin = (sockaddr_in*)&addr;
sin->sin_port = port;
sin->sin_port = (in_port_t)port;
} else {
sockaddr_in6* sin = (sockaddr_in6*)&addr;
sin->sin6_port = port;
sin->sin6_port = (in_port_t)port;
}
#endif
return 0;
Expand Down Expand Up @@ -309,7 +309,7 @@ int RPC_CLIENT::send_request(const char* p) {
buf = "<boinc_gui_rpc_request>\n";
buf += p;
buf += "</boinc_gui_rpc_request>\n\003";
int n = send(sock, buf.c_str(), (int)buf.size(), 0);
int n = (int)send(sock, buf.c_str(), (int)buf.size(), 0);
if (n < 0) {
//printf("send: %d\n", n);
//perror("send");
Expand All @@ -327,7 +327,7 @@ int RPC_CLIENT::get_reply(char*& mbuf) {

mf.puts(""); // make sure buffer is non-NULL
while (1) {
n = recv(sock, buf, 8192, 0);
n = (int) recv(sock, buf, 8192, 0);
if (n <= 0) return ERR_READ;
buf[n]=0;
mf.puts(buf);
Expand Down
4 changes: 2 additions & 2 deletions lib/gui_rpc_client_print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ void HOST_INFO::print() {
}
if (ci.have_opencl) {
ci.opencl_prop.peak_flops = ci.peak_flops;
ci.opencl_prop.opencl_available_ram = ci.opencl_prop.global_mem_size;
ci.opencl_prop.opencl_available_ram = (double)ci.opencl_prop.global_mem_size;
ci.opencl_prop.is_used = COPROC_USED;
ci.opencl_prop.description(buf, sizeof(buf), "Intel GPU");
printf(" %s\n", buf);
Expand All @@ -312,7 +312,7 @@ void HOST_INFO::print() {
}
if (cap.have_opencl) {
cap.opencl_prop.peak_flops = cap.peak_flops;
cap.opencl_prop.opencl_available_ram = cap.opencl_prop.global_mem_size;
cap.opencl_prop.opencl_available_ram = (double)cap.opencl_prop.global_mem_size;
cap.opencl_prop.is_used = COPROC_USED;
cap.opencl_prop.description(buf, sizeof(buf), "Apple GPU");
printf(" %s\n", buf);
Expand Down
2 changes: 1 addition & 1 deletion lib/mem_usage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ int mem_usage(double& vm_usage, double& resident_set) {
int i;
unsigned long tmp;

i = fread(buf, sizeof(char), 255, f);
i = (int)fread(buf, sizeof(char), 255, f);
buf[i] = '\0'; // terminate string
p = &buf[0];

Expand Down
4 changes: 2 additions & 2 deletions lib/msg_queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ int create_message_queue(key_t key) {
}

int receive_message(key_t key, void *msg, size_t msg_size, bool wait) {
int mq_id, retval;
int mq_id;

mq_id = msgget(key, 0666);
if (mq_id < 0) {
boinc::perror("receive_message: msgget");
return -1;
}

retval = msgrcv(mq_id, msg, msg_size, 0, (wait?0:IPC_NOWAIT));
ssize_t retval = msgrcv(mq_id, msg, msg_size, 0, (wait?0:IPC_NOWAIT));
if (retval < 0) {
boinc::perror("receive_message: msgrcv");
return -1;
Expand Down
6 changes: 3 additions & 3 deletions lib/opencl_boinc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int OPENCL_DEVICE_PROP::parse(XML_PARSER& xp, const char* end_tag) {
if (xp.parse_str("name", name, sizeof(name))) continue;
if (xp.parse_str("vendor", vendor, sizeof(vendor))) continue;
if (xp.parse_ulonglong("vendor_id", ull)) {
vendor_id = ull;
vendor_id = (unsigned)ull;
continue;
}
if (xp.parse_int("available", n)) {
Expand Down Expand Up @@ -251,7 +251,7 @@ int OPENCL_DEVICE_PROP::get_opencl_driver_revision() {
rev=0;
}
}
opencl_driver_revision=floor(rev*100+0.5);
opencl_driver_revision = (int)floor(rev*100+0.5);
return 0;
}

Expand All @@ -265,7 +265,7 @@ void OPENCL_DEVICE_PROP::description(char* buf, int buflen, const char* type) {
snprintf(s2, sizeof(s2),
"%.64s (driver version %.64s, device version %.64s, %.2fGB, %.2fGB available, %.0f GFLOPS peak)",
name, opencl_driver_version,
s1, global_mem_size/GIGA,
s1, (double)global_mem_size/GIGA,
opencl_available_ram/GIGA, peak_flops/1.e9
);

Expand Down
Loading