diff --git a/binr/rabin2/Makefile b/binr/rabin2/Makefile index bb4eb78283..c859ca054c 100644 --- a/binr/rabin2/Makefile +++ b/binr/rabin2/Makefile @@ -11,6 +11,7 @@ include ../../libr/main/deps.mk include ../../shlr/zip/deps.mk include ../../shlr/gdb/deps.mk include ../../shlr/java/deps.mk +include ../../shlr/grub/deps.mk include ../../shlr/bochs/deps.mk include ../../shlr/qnx/deps.mk include ../../shlr/ar/deps.mk diff --git a/binr/radare2/Makefile b/binr/radare2/Makefile index bf0249d9d6..0e13e2e9e4 100644 --- a/binr/radare2/Makefile +++ b/binr/radare2/Makefile @@ -19,7 +19,7 @@ ifeq (${COMPILER},emscripten) # https://kripken.github.io/emscripten-site/docs/optimizing/Optimizing-Code.html # -s INLINING_LIMIT=1 # --memory-init-file 0 -CFLAGS+=-s EXPORTED_FUNCTIONS='["_r2_asmjs_new", "_r2_asmjs_cmd", "_r2_asmjs_free", "_r2_asmjs_openurl"]' +CFLAGS+=-s EXPORTED_FUNCTIONS='["_r_core_new", "_r_core_free", "_r_cmd_str"]' CFLAGS+=-s EXTRA_EXPORTED_RUNTIME_METHODS='["cwrap", "addOnInit"]' CFLAGS+=-s TOTAL_MEMORY=33554432 CFLAGS+=-s ALLOW_MEMORY_GROWTH=1 diff --git a/binr/rules.mk b/binr/rules.mk index 8d10c70c69..70076d70f0 100644 --- a/binr/rules.mk +++ b/binr/rules.mk @@ -8,7 +8,15 @@ endif CFLAGS+=-I$(LTOP)/include ifeq (${COMPILER},emscripten) -EXT_EXE=.js +LINK+=../../libr/libr.a +LINK+=../../shlr/sdb/src/libsdb.a +LINK+=../../shlr/capstone/libcapstone.a +CFLAGS+= -s SIDE_MODULE=1 +#CFLAGS+=-s ERROR_ON_UNDEFINED_SYMBOLS=0 +#EXT_EXE=.js +#EXT_EXE=.html +EXT_EXE=.bc +#EXT_EXE=.wasm endif ifeq ($(USE_RPATH),1) diff --git a/libr/Makefile b/libr/Makefile index 582ada1eee..a5269e3423 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -95,7 +95,7 @@ _libr.${EXT_AR}: .libr BN=`basename $$LIB` ; \ echo $$BN ; \ mkdir -p .libr2/$$BN ; \ - ( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ar x ../../$$LIB ) ; \ + ( cd .libr2/$$BN ; pwd ; du -hs ../../$$LIB; ${AR} x ../../$$LIB ) ; \ done libr.${EXT_AR}: .libr2 @@ -122,10 +122,14 @@ E+=../shlr/capstone/libcapstone.${EXT_AR} endif libr.${EXT_SO}: .libr2 +ifeq (${COMPILER},emscripten) + echo nothing to do here +else $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \ .libr2/*/*.o \ ../shlr/gdb/lib/libgdbr.${EXT_AR} ../shlr/java/libr_java.${EXT_AR} \ ../shlr/libr_shlr.${EXT_AR} $(E) +endif #libr.${EXT_SO}: .libr # $(CC) -fvisibility=hidden $(MLFLAGS) ${LINK} ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} -shared -dynamiclib -o libr.${EXT_SO} \ diff --git a/libr/fs/fs.c b/libr/fs/fs.c index fa352f0917..f661b8eb8c 100644 --- a/libr/fs/fs.c +++ b/libr/fs/fs.c @@ -99,8 +99,6 @@ R_API void r_fs_del(RFS* fs, RFSPlugin* p) { R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 delta) { RFSPlugin* p; RFSRoot* root; - RFSFile* file; - RList* list; RListIter* iter; char* str; int len, lenstr; @@ -147,7 +145,7 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de return NULL; } } - file = r_fs_open (fs, str, false); + RFSFile* file = r_fs_open (fs, str, false); if (file) { r_fs_close (fs, file); eprintf ("r_fs_mount: Invalid mount point\n"); @@ -155,7 +153,7 @@ R_API RFSRoot* r_fs_mount(RFS* fs, const char* fstype, const char* path, ut64 de free (str); return NULL; } - list = r_fs_dir (fs, str); + RList *list = r_fs_dir (fs, str); if (!r_list_empty (list)) { //XXX: list need free ?? eprintf ("r_fs_mount: Invalid mount point\n"); @@ -552,7 +550,10 @@ static RFSPartitionType partitions[] = { {"dos", &fs_part_dos, fs_parhook}, #if USE_GRUB /* WARNING GPL code */ +#if !__EMSCRIPTEN__ +// wtf for some reason is not available on emscripten {"msdos", &grub_msdos_partition_map, grub_parhook}, +#endif {"apple", &grub_apple_partition_map, grub_parhook}, {"sun", &grub_sun_partition_map, grub_parhook}, {"sunpc", &grub_sun_pc_partition_map, grub_parhook}, diff --git a/libr/include/r_types.h b/libr/include/r_types.h index dbdf7f4e5f..e79703f2bf 100644 --- a/libr/include/r_types.h +++ b/libr/include/r_types.h @@ -110,6 +110,10 @@ # define UNUSED_FUNCTION(x) UNUSED_ ## x #endif +#ifdef __EMSCRIPTEN__ +# define __UNIX__ 1 +#endif + #ifdef __HAIKU__ # define __UNIX__ 1 #endif diff --git a/libr/include/sdb/ht_inc.h b/libr/include/sdb/ht_inc.h index 7707701d6e..892f4977f4 100644 --- a/libr/include/sdb/ht_inc.h +++ b/libr/include/sdb/ht_inc.h @@ -1,5 +1,9 @@ /* radare2 - BSD 3 Clause License - 2016 - crowell */ +#ifndef HT_TYPE +#error HT_TYPE should be defined before including this header +#endif + #undef HtName_ #undef Ht_ #undef HT_ @@ -8,10 +12,6 @@ #undef KEY_TO_HASH #undef HT_NULL_VALUE -#ifndef HT_TYPE -#error HT_TYPE should be defined before including this header -#endif - #if HT_TYPE == 1 #define HtName_(name) name##PP #define Ht_(name) ht_pp_##name @@ -106,5 +106,3 @@ SDB_API void Ht_(foreach)(HtName_(Ht) *ht, HT_(ForeachCallback) cb, void *user); SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found); SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update); - -#undef HT_TYPE diff --git a/libr/include/sdb/ht_pp.h b/libr/include/sdb/ht_pp.h index e4f879ed82..45a4db6dd1 100644 --- a/libr/include/sdb/ht_pp.h +++ b/libr/include/sdb/ht_pp.h @@ -11,5 +11,6 @@ SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); +#undef HT_TYPE #endif diff --git a/libr/include/sdb/ht_up.h b/libr/include/sdb/ht_up.h index 4bb0006872..0b09258862 100644 --- a/libr/include/sdb/ht_up.h +++ b/libr/include/sdb/ht_up.h @@ -11,5 +11,6 @@ SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); +#undef HT_TYPE #endif diff --git a/libr/include/sdb/ht_uu.h b/libr/include/sdb/ht_uu.h index 7f7d13423b..ee042a6383 100644 --- a/libr/include/sdb/ht_uu.h +++ b/libr/include/sdb/ht_uu.h @@ -9,5 +9,6 @@ #include "ht_inc.h" SDB_API HtName_(Ht)* Ht_(new0)(void); +#undef HT_TYPE #endif diff --git a/libr/util/pkcs7.c b/libr/util/pkcs7.c index 35fc203340..5e00215f4d 100644 --- a/libr/util/pkcs7.c +++ b/libr/util/pkcs7.c @@ -5,7 +5,7 @@ #include #include "./x509.h" -extern void *r_x509_name_json (PJ *pj, RX509Name *name); +extern void r_x509_name_json (PJ *pj, RX509Name *name); extern void r_x509_free_crl (RX509CertificateRevocationList *crl); extern void r_x509_crlentry_dump (RX509CRLEntry *crle, const char *pad, RStrBuf *sb); static bool r_pkcs7_parse_attributes(RPKCS7Attributes *attribute, RASN1Object *object); diff --git a/libr/util/prof.c b/libr/util/prof.c index 50e091c7b0..3095217648 100644 --- a/libr/util/prof.c +++ b/libr/util/prof.c @@ -1,6 +1,7 @@ -/* radare - LGPL - Copyright 2009-2012 - pancake */ +/* radare - LGPL - Copyright 2009-2019 - pancake */ #include "r_util.h" + typedef struct timeval tv; // Subtract the 'tv' values begin from end, storing result in RESULT diff --git a/shlr/grub/deps.mk b/shlr/grub/deps.mk new file mode 100644 index 0000000000..c172a947ed --- /dev/null +++ b/shlr/grub/deps.mk @@ -0,0 +1,2 @@ +LINK+=$(SHLR)/grub/libgrubfs.$(EXT_AR) +#CFLAGS+=-I$(SHLR)/zip/include diff --git a/shlr/sdb/src/ht_inc.h b/shlr/sdb/src/ht_inc.h index 7707701d6e..892f4977f4 100644 --- a/shlr/sdb/src/ht_inc.h +++ b/shlr/sdb/src/ht_inc.h @@ -1,5 +1,9 @@ /* radare2 - BSD 3 Clause License - 2016 - crowell */ +#ifndef HT_TYPE +#error HT_TYPE should be defined before including this header +#endif + #undef HtName_ #undef Ht_ #undef HT_ @@ -8,10 +12,6 @@ #undef KEY_TO_HASH #undef HT_NULL_VALUE -#ifndef HT_TYPE -#error HT_TYPE should be defined before including this header -#endif - #if HT_TYPE == 1 #define HtName_(name) name##PP #define Ht_(name) ht_pp_##name @@ -106,5 +106,3 @@ SDB_API void Ht_(foreach)(HtName_(Ht) *ht, HT_(ForeachCallback) cb, void *user); SDB_API HT_(Kv)* Ht_(find_kv)(HtName_(Ht)* ht, const KEY_TYPE key, bool* found); SDB_API bool Ht_(insert_kv)(HtName_(Ht) *ht, HT_(Kv) *kv, bool update); - -#undef HT_TYPE diff --git a/shlr/sdb/src/ht_pp.c b/shlr/sdb/src/ht_pp.c index 7721236ce2..09bbeb80d6 100644 --- a/shlr/sdb/src/ht_pp.c +++ b/shlr/sdb/src/ht_pp.c @@ -1,6 +1,5 @@ -#include "ht_pp.h" #include "sdb.h" - +#include "ht_pp.h" #include "ht_inc.c" static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) { diff --git a/shlr/sdb/src/ht_pp.h b/shlr/sdb/src/ht_pp.h index e4f879ed82..45a4db6dd1 100644 --- a/shlr/sdb/src/ht_pp.h +++ b/shlr/sdb/src/ht_pp.h @@ -11,5 +11,6 @@ SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); +#undef HT_TYPE #endif diff --git a/shlr/sdb/src/ht_up.c b/shlr/sdb/src/ht_up.c index afd8c8b1b3..0af1f7ad14 100644 --- a/shlr/sdb/src/ht_up.c +++ b/shlr/sdb/src/ht_up.c @@ -1,5 +1,4 @@ #include "ht_up.h" - #include "ht_inc.c" static HtName_(Ht)* internal_ht_default_new(ut32 size, ut32 prime_idx, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) calcsizeV) { diff --git a/shlr/sdb/src/ht_up.h b/shlr/sdb/src/ht_up.h index 4bb0006872..0b09258862 100644 --- a/shlr/sdb/src/ht_up.h +++ b/shlr/sdb/src/ht_up.h @@ -11,5 +11,6 @@ SDB_API HtName_(Ht)* Ht_(new0)(void); SDB_API HtName_(Ht)* Ht_(new)(HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); SDB_API HtName_(Ht)* Ht_(new_size)(ut32 initial_size, HT_(DupValue) valdup, HT_(KvFreeFunc) pair_free, HT_(CalcSizeV) valueSize); +#undef HT_TYPE #endif diff --git a/shlr/sdb/src/ht_uu.h b/shlr/sdb/src/ht_uu.h index 7f7d13423b..ee042a6383 100644 --- a/shlr/sdb/src/ht_uu.h +++ b/shlr/sdb/src/ht_uu.h @@ -9,5 +9,6 @@ #include "ht_inc.h" SDB_API HtName_(Ht)* Ht_(new0)(void); +#undef HT_TYPE #endif diff --git a/shlr/sdb/src/json/js0n.c b/shlr/sdb/src/json/js0n.c index 32d71a8345..1d04d3a7e2 100644 --- a/shlr/sdb/src/json/js0n.c +++ b/shlr/sdb/src/json/js0n.c @@ -9,141 +9,15 @@ #define CAP(i) if(depth == 1) prev = *out++ = ((cur+i) - (js + prev) + 1) #ifdef _MSC_VER -#define GO_DOWN (1) -#define GO_UP (1 << 1) -#define GO_Q_DOWN (1 << 2) -#define GO_Q_UP (1 << 3) -#define GO_BARE (1 << 4) -#define GO_UNBARE (1 << 5) -#define GO_ESCAPE (1 << 6) -#define GO_UNESCAPE (1 << 7) -#define GO_UTF8 (1 << 8) -#define GO_UTF8_CONTINUE (1 << 9) -int sdb_js0n(const ut8 *js, RangstrType len, RangstrType *out) { - ut32 prev = 0; - const ut8 *cur, *end; - int depth = 0, utf8_remain = 0, what_did = 1; - for (cur = js, end = js + len; cur < end; cur++) { - if (what_did & GO_BARE) { - switch (*cur) { - case ' ': - case '\t': - case '\r': - case '\n': - case ',': - case ']': - case '}': - what_did = GO_UNBARE; - CAP (-1); - break; - default: - if (*cur >= 32 && *cur <= 126) { - continue; - } - return 1; - } - // Same *cur - } - if (what_did & GO_UTF8) { - if (*cur < 128 || (*cur >=192 && *cur <= 255)) { - return 1; - } - if (!--utf8_remain) { - what_did = GO_UTF8_CONTINUE; - } - continue; - } - if (what_did & GO_ESCAPE) { - switch (*cur) { - case '"': - case '\\': - case '/': - case 'b': - case 'f': - case 'n': - case 'r': - case 't': - case 'u': - what_did = GO_UNESCAPE; - break; - default: - return 1; - } - continue; - } - if (what_did & GO_Q_UP || what_did & GO_UTF8_CONTINUE || what_did & GO_UNESCAPE) { - switch (*cur) { - case '\\': - what_did = GO_ESCAPE; - break; - case '"': - what_did = GO_Q_DOWN; - CAP (-1); - break; - default: - if (*cur <= 31 || (*cur >= 127 && *cur <= 191) || (*cur >= 248 && *cur <= 255)) { - return 1; - } - if (*cur < 127) { - continue; - } - what_did = GO_UTF8; - if (*cur < 224) { - utf8_remain = 1; - continue; - } - if (*cur < 239) { - utf8_remain = 2; - continue; - } - utf8_remain = 3; - break; - } - continue; - } - switch (*cur) { - case '\t': - case ' ': - case '\r': - case '\n': - case ',': - case ':': - break; - case '"': - PUSH (1); - what_did = GO_Q_UP; - break; - case '[': - case '{': - PUSH (0); - ++depth; - what_did = GO_UP; - break; - case ']': - case '}': - --depth; - CAP (0); - what_did = GO_DOWN; - break; - case '-': - case 't': - case 'f': - case 'n': - what_did = GO_BARE; - PUSH (0); - break; - default: - if (*cur >= 48 && *cur <= 57) { // 0-9 - what_did = GO_BARE; - PUSH (0); - break; - } - return 1; - } - } - return depth; -} +#define HAVE_COMPUTED_GOTOS 0 +#elif __EMSCRIPTEN__ +#define HAVE_COMPUTED_GOTOS 0 #else +#define HAVE_COMPUTED_GOTOS 1 +#endif + +#if HAVE_COMPUTED_GOTOS + #if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) #pragma GCC diagnostic push #endif @@ -281,4 +155,141 @@ l_utf_continue: go = gostring; goto l_loop; } -#endif + +#else // HAVE_COMPUTED_GOTOS + +#define GO_DOWN (1) +#define GO_UP (1 << 1) +#define GO_Q_DOWN (1 << 2) +#define GO_Q_UP (1 << 3) +#define GO_BARE (1 << 4) +#define GO_UNBARE (1 << 5) +#define GO_ESCAPE (1 << 6) +#define GO_UNESCAPE (1 << 7) +#define GO_UTF8 (1 << 8) +#define GO_UTF8_CONTINUE (1 << 9) +int sdb_js0n(const ut8 *js, RangstrType len, RangstrType *out) { + ut32 prev = 0; + const ut8 *cur, *end; + int depth = 0, utf8_remain = 0, what_did = 1; + for (cur = js, end = js + len; cur < end; cur++) { + if (what_did & GO_BARE) { + switch (*cur) { + case ' ': + case '\t': + case '\r': + case '\n': + case ',': + case ']': + case '}': + what_did = GO_UNBARE; + CAP (-1); + break; + default: + if (*cur >= 32 && *cur <= 126) { + continue; + } + return 1; + } + // Same *cur + } + if (what_did & GO_UTF8) { + if (*cur < 128 || (*cur >=192 && *cur <= 255)) { + return 1; + } + if (!--utf8_remain) { + what_did = GO_UTF8_CONTINUE; + } + continue; + } + if (what_did & GO_ESCAPE) { + switch (*cur) { + case '"': + case '\\': + case '/': + case 'b': + case 'f': + case 'n': + case 'r': + case 't': + case 'u': + what_did = GO_UNESCAPE; + break; + default: + return 1; + } + continue; + } + if (what_did & GO_Q_UP || what_did & GO_UTF8_CONTINUE || what_did & GO_UNESCAPE) { + switch (*cur) { + case '\\': + what_did = GO_ESCAPE; + break; + case '"': + what_did = GO_Q_DOWN; + CAP (-1); + break; + default: + if (*cur <= 31 || (*cur >= 127 && *cur <= 191) || (*cur >= 248 && *cur <= 255)) { + return 1; + } + if (*cur < 127) { + continue; + } + what_did = GO_UTF8; + if (*cur < 224) { + utf8_remain = 1; + continue; + } + if (*cur < 239) { + utf8_remain = 2; + continue; + } + utf8_remain = 3; + break; + } + continue; + } + switch (*cur) { + case '\t': + case ' ': + case '\r': + case '\n': + case ',': + case ':': + break; + case '"': + PUSH (1); + what_did = GO_Q_UP; + break; + case '[': + case '{': + PUSH (0); + ++depth; + what_did = GO_UP; + break; + case ']': + case '}': + --depth; + CAP (0); + what_did = GO_DOWN; + break; + case '-': + case 't': + case 'f': + case 'n': + what_did = GO_BARE; + PUSH (0); + break; + default: + if (*cur >= 48 && *cur <= 57) { // 0-9 + what_did = GO_BARE; + PUSH (0); + break; + } + return 1; + } + } + return depth; +} +#endif // HAVE_COMPUTED_GOTOS diff --git a/shlr/sdb/src/main.c b/shlr/sdb/src/main.c index 2e49b4354a..083ac45a0c 100644 --- a/shlr/sdb/src/main.c +++ b/shlr/sdb/src/main.c @@ -1,4 +1,4 @@ -/* sdb - MIT - Copyright 2011-2017 - pancake */ +/* sdb - MIT - Copyright 2011-2019 - pancake */ #include #include @@ -24,7 +24,7 @@ static void terminate(int sig UNUSED) { exit (1); } sdb_free (s); - exit (0); + exit (sig<2?sig:0); } #define BS 128 @@ -142,11 +142,9 @@ static char *stdin_slurp(int *sz) { if (sz) { *sz = len; } - //eprintf ("LEN %d (%s)\n", len, buf); if (len < 1) { free (buf); - buf = NULL; - return NULL; + return buf = NULL; } buf[len] = 0; return buf; @@ -155,9 +153,8 @@ static char *stdin_slurp(int *sz) { #if USE_MMAN static void synchronize(int sig UNUSED) { // TODO: must be in sdb_sync() or wat? - Sdb *n; sdb_sync (s); - n = sdb_new (s->path, s->name, s->lock); + Sdb *n = sdb_new (s->path, s->name, s->lock); if (n) { sdb_config (n, options); sdb_free (s); @@ -165,23 +162,22 @@ static void synchronize(int sig UNUSED) { } } #endif -static int sdb_grep_dump(const char *db, int fmt, bool grep, + +static int sdb_grep_dump(const char *dbname, int fmt, bool grep, const char *expgrep) { - char *v; - char k[SDB_MAX_KEY] = { - 0 - }; + char *v, k[SDB_MAX_KEY] = { 0 }; const char *comma = ""; - Sdb *s = sdb_new (NULL, db, 0); - if (!s) { + // local db beacuse is readonly and we dont need to finalize in case of ^C + Sdb *db = sdb_new (NULL, dbname, 0); + if (!db) { return 1; } - sdb_config (s, options); - sdb_dump_begin (s); + sdb_config (db, options); + sdb_dump_begin (db); if (fmt == MODE_JSON) { printf ("{"); } - while (sdb_dump_dupnext (s, k, &v, NULL)) { + while (sdb_dump_dupnext (db, k, &v, NULL)) { if (grep && !strstr (k, expgrep) && !strstr (v, expgrep)) { free (v); continue; @@ -218,9 +214,10 @@ static int sdb_grep_dump(const char *db, int fmt, bool grep, printf ("}\n"); break; } - sdb_free (s); + sdb_free (db); return 0; } + static int sdb_grep(const char *db, int fmt, const char *grep) { return sdb_grep_dump (db, fmt, true, grep); } @@ -401,7 +398,7 @@ int showcount(const char *db) { int main(int argc, const char **argv) { char *line; const char *arg, *grep = NULL; - int i, ret, fmt = MODE_DFLT; + int i, fmt = MODE_DFLT; int db0 = 1, argi = 1; bool interactive = false; @@ -484,7 +481,7 @@ int main(int argc, const char **argv) { signal (SIGINT, terminate); signal (SIGHUP, synchronize); #endif - ret = 0; + int ret = 0; if (interactive || !strcmp (argv[db0 + 1], "-")) { if ((s = sdb_new (NULL, argv[db0], 0))) { sdb_config (s, options); @@ -517,6 +514,6 @@ int main(int argc, const char **argv) { } } } - terminate (0); + terminate (ret); return ret; } diff --git a/shlr/sdb/src/query.c b/shlr/sdb/src/query.c index 113d8ec8d1..9cb827d457 100644 --- a/shlr/sdb/src/query.c +++ b/shlr/sdb/src/query.c @@ -307,13 +307,15 @@ next_quote: SdbListIter *it; SdbNs *ns; ls_foreach (s->ns, it, ns) { - int len = strlen (ns->name); - if (len<(long)sizeof (root)) { - memcpy (root, ns->name, len+1); + int name_len = strlen (ns->name); + if (name_len < (long)sizeof (root)) { + memcpy (root, ns->name, name_len + 1); walk_namespace (out, root, - sizeof (root)-len, - root+len, ns, encode); - } else eprintf ("TODO: Namespace too long\n"); + sizeof (root) - name_len, + root + name_len, ns, encode); + } else { + eprintf ("TODO: Namespace too long\n"); + } } goto fail; } else diff --git a/shlr/sdb/src/sdb.c b/shlr/sdb/src/sdb.c index b8741f0fdf..ea9736a69b 100644 --- a/shlr/sdb/src/sdb.c +++ b/shlr/sdb/src/sdb.c @@ -947,7 +947,7 @@ SDB_API bool sdb_dump_dupnext(Sdb* s, char *key, char **value, int *_vlen) { } if (value) { *value = 0; - if (vlen >= SDB_MIN_VALUE && vlen < SDB_MAX_VALUE) { + if (vlen < SDB_MAX_VALUE) { *value = malloc (vlen + 10); if (!*value) { return false; diff --git a/shlr/zip/zip/zip_fdopen.c b/shlr/zip/zip/zip_fdopen.c index bda9aabac4..50b663de71 100644 --- a/shlr/zip/zip/zip_fdopen.c +++ b/shlr/zip/zip/zip_fdopen.c @@ -33,6 +33,7 @@ +#include #include "zipint.h"