gcc8 warnings (fixes #10338) (#11798)

* bin/format/pe: fix gcc8 warnings
* bin/p: fix gcc8 warnings
* io/io_r2pipe: fix gcc8 warnings and style
* clang-format: do not sort includes, it may break stuff
* use sizeof instead of macros
This commit is contained in:
Riccardo Schirone 2018-10-13 01:32:20 +02:00 committed by radare
parent daddf534e3
commit 8153422add
6 changed files with 30 additions and 17 deletions

View file

@ -21,3 +21,4 @@ AlignTrailingComments: false
AlignOperands: false
Cpp11BracedListStyle: false
ForEachMacros: ['r_list_foreach', 'ls_foreach', 'fcn_tree_foreach_intersect', 'r_skiplist_foreach', 'graph_foreach_anode']
SortIncludes: false

View file

@ -472,9 +472,12 @@ static int bin_pe_parse_imports(struct PE_(r_bin_pe_obj_t)* bin,
break;
}
name[PE_NAME_LENGTH] = '\0';
snprintf (import_name, PE_NAME_LENGTH, "%s_%s", dll_name, name);
int len = snprintf (import_name, sizeof (import_name), "%s_%s", dll_name, name);
if (len >= sizeof (import_name)) {
eprintf ("Import name '%s' has been truncated.\n", import_name);
}
}
if (!(*importp = realloc (*importp, (*nimp + 1) * sizeof(struct r_bin_pe_import_t)))) {
if (!(*importp = realloc (*importp, (*nimp + 1) * sizeof (struct r_bin_pe_import_t)))) {
r_sys_perror ("realloc (import)");
goto error;
}
@ -2713,13 +2716,16 @@ struct r_bin_pe_export_t* PE_(r_bin_pe_get_exports)(struct PE_(r_bin_pe_obj_t)*
}
dll_name[PE_NAME_LENGTH] = '\0';
function_name[PE_NAME_LENGTH] = '\0';
snprintf (export_name, sizeof (export_name) - 1, "%s_%s", dll_name, function_name);
int len = snprintf (export_name, sizeof (export_name), "%s_%s", dll_name, function_name);
if (len >= sizeof (export_name)) {
eprintf ("Export name '%s' has been truncated\n", export_name);
}
exports[i].vaddr = bin_pe_rva_to_va (bin, function_rva);
exports[i].paddr = bin_pe_rva_to_paddr (bin, function_rva);
exports[i].ordinal = function_ordinal;
memcpy (exports[i].forwarder, forwarder_name, PE_NAME_LENGTH);
exports[i].forwarder[PE_NAME_LENGTH] = '\0';
memcpy (exports[i].name, export_name, PE_NAME_LENGTH);
memcpy (exports[i].name, export_name, PE_NAME_LENGTH);
exports[i].name[PE_NAME_LENGTH] = '\0';
exports[i].last = 0;
}

View file

@ -834,7 +834,7 @@ static void *load_buffer(RBinFile *bf, RBuffer *buf, ut64 loadaddr, Sdb *sdb) {
}
RDyldCache *cache = R_NEW0 (RDyldCache);
strncpy ((char*) cache->magic, "dyldcac", 7);
memcpy (cache->magic, "dyldcac", 7);
cache->buf = fbuf;
cache->hdr = read_cache_header (fbuf);
if (!cache->hdr) {

View file

@ -55,9 +55,9 @@ static RList *sections(RBinFile *bf) {
sections[i] = R_NEW0 (RBinSection);
/* Firmware Type ('0'=ARM9/'1'=ARM11) */
if (loaded_header.sections[i].type == 0x0) {
strncpy (sections[i]->name, "arm9", 4);
strncpy (sections[i]->name, "arm9", sizeof (sections[i]->name));
} else if (loaded_header.sections[i].type == 0x1) {
strncpy (sections[i]->name, "arm11", 5);
strncpy (sections[i]->name, "arm11", sizeof (sections[i]->name));
} else {
corrupt = true;
break;

View file

@ -6,12 +6,14 @@
#include <r_endian.h>
static bool check_bytes(const ut8 *buf, ut64 length) {
const ut8* buf_hdr = buf;
const ut8 *buf_hdr = buf;
ut16 cksum1, cksum2;
if ((length & 0x8000) == 0x200) {
buf_hdr += 0x200;
}
// FIXME: this was commented out because it always evaluates to false.
// Need to be fixed by someone with SFC knowledge
// if ((length & 0x8000) == 0x200) {
// buf_hdr += 0x200;
// }
if (length < 0x8000) {
return false;
}

View file

@ -22,16 +22,20 @@ static int __write(RIO *io, RIODesc *fd, const ut8 *buf, int count) {
}
bufn = bufnum;
*bufn = 0;
for (i=0; i<count; i++) {
int bufn_sz = sizeof (bufnum) - (bufn-bufnum);
snprintf (bufn, bufn_sz, "%s%d", i?",":"", buf[i]);
for (i = 0; i < count; i++) {
int bufn_sz = sizeof (bufnum) - (bufn - bufnum);
snprintf (bufn, bufn_sz, "%s%d", i ? "," : "", buf[i]);
bufn += strlen (bufn);
}
snprintf (fmt, sizeof (fmt),
"{\"op\":\"write\",\"address\":%"PFMT64d",\"data\":[%s]}",
int len = snprintf (fmt, sizeof (fmt),
"{\"op\":\"write\",\"address\":%" PFMT64d ",\"data\":[%s]}",
io->off, bufnum);
if (len >= sizeof (fmt)) {
eprintf ("r2p_write: error, fmt string has been truncated\n");
return -1;
}
rv = r2p_write (R2P (fd), fmt);
if (rv <1) {
if (rv < 1) {
eprintf ("r2p_write: error\n");
return -1;
}