From 8b955b5e9214dd8f1bea95242359391d5678a971 Mon Sep 17 00:00:00 2001 From: TLINDEN Date: Tue, 25 Feb 2014 18:05:32 +0100 Subject: [PATCH] added -Wextra -Werror and fixed everything it had to mecker about --- bindings/cpp/key.cpp | 5 +++- configure.ac | 1 + include/pcp.h | 1 + include/pcp/pcpstream.h | 2 +- include/pcp/vault.h | 4 +-- libpcp/base85.c | 2 +- libpcp/crypto.c | 4 +-- libpcp/ed.c | 2 +- libpcp/mgmt.c | 1 - libpcp/pad.c | 4 +-- libpcp/pcpstream.c | 58 +++-------------------------------------- libpcp/scrypt.c | 2 +- libpcp/vault.c | 4 +-- libpcp/z85.c | 2 +- src/keymgmt.c | 2 +- src/keymgmt.h | 2 +- src/keyprint.c | 17 +++++++----- src/pcp.c | 2 +- tests/invalidkeys.c | 2 +- 19 files changed, 36 insertions(+), 81 deletions(-) diff --git a/bindings/cpp/key.cpp b/bindings/cpp/key.cpp index 9614216..b2872a7 100644 --- a/bindings/cpp/key.cpp +++ b/bindings/cpp/key.cpp @@ -32,7 +32,10 @@ Key::Key() { Key::Key(bool generate) { stored = false; - K = pcpkey_new(); + if(generate) + K = pcpkey_new(); + else + K = NULL; } Key::Key(const string& passphrase) { diff --git a/configure.ac b/configure.ac index 603d983..c895615 100755 --- a/configure.ac +++ b/configure.ac @@ -282,6 +282,7 @@ if test -n "$bigendian"; then CFLAGS="$CFLAGS -D__CPU_IS_BIG_ENDIAN=1" fi +CFLAGS="$CFLAGS -Werror -Wextra" CXXFLAGS="$CFLAGS" AC_SUBST(PACKAGE_VERSION) diff --git a/include/pcp.h b/include/pcp.h index 8b16eae..fb0d6c6 100644 --- a/include/pcp.h +++ b/include/pcp.h @@ -8,6 +8,7 @@ extern "C" { #include "pcp/config.h" #include "pcp/base85.h" #include "pcp/buffer.h" +#include "pcp/config.h" #include "pcp/crypto.h" #include "pcp/defines.h" #include "pcp/digital_crc32.h" diff --git a/include/pcp/pcpstream.h b/include/pcp/pcpstream.h index a1f649f..65e9832 100644 --- a/include/pcp/pcpstream.h +++ b/include/pcp/pcpstream.h @@ -257,7 +257,7 @@ void ps_armor(Pcpstream *stream, size_t blocksize); /* read from primary source, decode z85 and out into cache. if buf != NULL, consider it as the start of encoded data and remove headers and comments, then continue as normal. */ -size_t ps_read_decode(Pcpstream *stream, Buffer *cache, void *buf, size_t bufsize); +size_t ps_read_decode(Pcpstream *stream, void *buf, size_t bufsize); /* determine if primary source is z85 encoded, put the data read from it into the cache */ diff --git a/include/pcp/vault.h b/include/pcp/vault.h index 46dc91c..269e042 100644 --- a/include/pcp/vault.h +++ b/include/pcp/vault.h @@ -239,8 +239,8 @@ int pcpvault_copy(vault_t *tmp, vault_t *vault); /* delete a vault file */ void pcpvault_unlink(vault_t *tmp); -/* calculate the vault checksum */ -byte *pcpvault_create_checksum(vault_t *vault); +/* calculate the checksum of the current vault */ +byte *pcpvault_create_checksum(); /* write the new checksum to the header of the current vault */ void pcpvault_update_checksum(vault_t *vault); diff --git a/libpcp/base85.c b/libpcp/base85.c index 5d4fb64..7cfc071 100644 --- a/libpcp/base85.c +++ b/libpcp/base85.c @@ -24,7 +24,7 @@ static char de85[256]; static void prep_base85(void) { - int i; + size_t i; if (de85['Z']) return; for (i = 0; i < ARRAY_SIZE(en85); i++) { diff --git a/libpcp/crypto.c b/libpcp/crypto.c index d8ee7bf..a928d1a 100644 --- a/libpcp/crypto.c +++ b/libpcp/crypto.c @@ -165,10 +165,10 @@ size_t pcp_decrypt_stream(Pcpstream *in, Pcpstream* out, pcp_key_t *s, byte *sym pcp_pubkey_t *cur = NULL; pcp_pubkey_t *sender = NULL; byte *reccipher = NULL; - int nrec, recmatch, self; + int recmatch, self; uint32_t lenrec; byte head[1]; - size_t cur_bufsize, rec_size; + size_t cur_bufsize, rec_size, nrec; byte rec_buf[PCP_ASYM_RECIPIENT_SIZE]; diff --git a/libpcp/ed.c b/libpcp/ed.c index c1f608c..7654e04 100644 --- a/libpcp/ed.c +++ b/libpcp/ed.c @@ -205,7 +205,7 @@ pcp_pubkey_t *pcp_ed_verify_buffered(Pcpstream *in, pcp_pubkey_t *p) { /* printf("offset: %ld, full: %ld, cur: %ld\n", offset, full_bufsize, cur_bufsize); */ - if(offset >= 0 && offset <= PCP_BLOCK_SIZE/2) { + if(offset > 0 && offset <= PCP_BLOCK_SIZE/2) { /* sig begins within the first half, adjust in_buf size */ /* printf("1st half\n"); */ next_bufsize = 0; diff --git a/libpcp/mgmt.c b/libpcp/mgmt.c index 8718ee6..d9c7257 100644 --- a/libpcp/mgmt.c +++ b/libpcp/mgmt.c @@ -467,7 +467,6 @@ Buffer *pcp_export_c_pub(pcp_key_t *sk) { struct tm *c; time_t t = time(0); c = localtime(&t); - size_t i; buffer_add_str(b, "/*\n * C export of public key\n"); buffer_add_str(b, " * Generated on: %04d-%02d-%02dT%02d:%02d:%02d\n", diff --git a/libpcp/pad.c b/libpcp/pad.c index ad785a1..fced620 100644 --- a/libpcp/pad.c +++ b/libpcp/pad.c @@ -28,7 +28,7 @@ void pcp_pad_prepend(byte **padded, byte *unpadded, byte *tmp = ucmalloc(unpadlen + padlen); /* pcp_append orig */ - int i; + size_t i; for(i=0; iarmor == 1) { /* fetch next chunk and decode it */ - return ps_read_decode(stream, stream->next, NULL, 0); + return ps_read_decode(stream, NULL, 0); } else { /* unencoded source, fetch as is */ @@ -192,7 +192,7 @@ void ps_determine(Pcpstream *stream) { if(_buffer_is_binary(buf, got) == 0) { /* no, it's armored */ stream->armor = 1; - ps_read_decode(stream, stream->cache, buf, got); + ps_read_decode(stream, buf, got); } else { /* just put the raw stuff into the cache */ @@ -200,8 +200,7 @@ void ps_determine(Pcpstream *stream) { } } -size_t ps_read_decode(Pcpstream *stream, Buffer *cache, void *buf, size_t bufsize) { - size_t zdiff = 1; +size_t ps_read_decode(Pcpstream *stream, void *buf, size_t bufsize) { size_t i = 0; uint8_t is_comment = 0; uint8_t c; @@ -247,57 +246,6 @@ size_t ps_read_decode(Pcpstream *stream, Buffer *cache, void *buf, size_t bufsiz return outlen; } -size_t ps_read_decodeOLD(Pcpstream *stream, Buffer *cache, void *buf, size_t bufsize) { - size_t zdiff = 1; - size_t i = 0; - Buffer *z = buffer_new(32, "ztemp"); - - if(bufsize > 0) { - /* remove newlines, comments and headers, if any */ - char *z85 = pcp_readz85string(buf, bufsize); - buffer_add(z, z85, strlen(z85)); - - /* check if we need to read more in order to get a full block */ - zdiff = stream->blocksize - strlen(z85); - i = strlen(z85); - free(z85); - } - - if(zdiff > 0) { - /* read in bytewise, ignore newlines and add until the block is full */ - uint8_t c; - while (i < stream->blocksize) { - if (ps_read_raw(stream, &c, 1) == 1) { - if(c != '\r' && c != '\n') { - buffer_add8(z, c); - i++; - } - } - else - break; - } - } - - /* finally, decode it and put into cache */ - size_t binlen, outlen; - byte *bin = pcp_z85_decode(buffer_get_str(z), &binlen); - if(bin == NULL) { - /* it's not z85 encoded, so threat it as binary */ - stream->armor = 1; - buffer_add_buf(stream->cache, z); - outlen = buffer_size(stream->cache); - } - else { - /* yes, successfully decoded it, put into cache */ - buffer_add(stream->cache, bin, binlen); - outlen = binlen; - } - - buffer_free(z); - - return outlen; -} - size_t ps_write(Pcpstream *stream, void *buf, size_t writebytes) { Buffer *z = buffer_new(32, "Pcpwritetemp"); diff --git a/libpcp/scrypt.c b/libpcp/scrypt.c index 1cad7a4..fe4fea8 100644 --- a/libpcp/scrypt.c +++ b/libpcp/scrypt.c @@ -30,7 +30,7 @@ byte* pcp_scrypt(char *passwd, size_t passwdlen, byte *nonce, size_t noncelen) { uint32_t p = 1; size_t buflen = 64; - if (crypto_scrypt(passwd, passwdlen, (uint8_t *)nonce, noncelen, N, r, p, dk, buflen) == 0) { + if (crypto_scrypt((byte *)passwd, passwdlen, (uint8_t *)nonce, noncelen, N, r, p, dk, buflen) == 0) { return dk; } else { diff --git a/libpcp/vault.c b/libpcp/vault.c index 463e804..88cacd8 100644 --- a/libpcp/vault.c +++ b/libpcp/vault.c @@ -255,7 +255,7 @@ int pcpvault_writeall(vault_t *vault) { } void pcpvault_update_checksum(vault_t *vault) { - byte *checksum = pcpvault_create_checksum(vault); + byte *checksum = pcpvault_create_checksum(); vault_header_t *header = ucmalloc(sizeof(vault_header_t)); header->fileid = PCP_VAULT_ID; @@ -270,7 +270,7 @@ void pcpvault_update_checksum(vault_t *vault) { fseek(vault->fd, 0, SEEK_END); } -byte *pcpvault_create_checksum(vault_t *vault) { +byte *pcpvault_create_checksum() { int numskeys = pcphash_count(); int numpkeys = pcphash_countpub(); diff --git a/libpcp/z85.c b/libpcp/z85.c index f795511..8bc7b6a 100644 --- a/libpcp/z85.c +++ b/libpcp/z85.c @@ -255,7 +255,7 @@ char *pcp_readz85file(FILE *infile) { } char *pcp_readz85string(byte *input, size_t bufsize) { - int i; + size_t i; size_t MAXLINE = 1024; if(bufsize == 0) { diff --git a/src/keymgmt.c b/src/keymgmt.c index 520c972..34017e0 100644 --- a/src/keymgmt.c +++ b/src/keymgmt.c @@ -428,7 +428,7 @@ void pcp_exportpublic(char *keyid, char *passwd, char *outfile, int format, int -int pcp_importsecret (vault_t *vault, FILE *in, char *passwd) { +int pcp_importsecret (FILE *in, char *passwd) { byte *buf = ucmalloc(2048); size_t buflen = fread(buf, 1, 2048, in); pcp_key_t *sk = NULL; diff --git a/src/keymgmt.h b/src/keymgmt.h index 4ee6e98..4a06aea 100644 --- a/src/keymgmt.h +++ b/src/keymgmt.h @@ -58,7 +58,7 @@ char *pcp_normalize_id(char *keyid); pcp_key_t *pcp_find_primary_secret(); int pcp_importpublic (vault_t *vault, FILE *in); -int pcp_importsecret (vault_t *vault, FILE *in, char *passwd); +int pcp_importsecret (FILE *in, char *passwd); void pcpdelete_key(char *keyid); char *pcp_find_id_byrec(char *recipient); diff --git a/src/keyprint.c b/src/keyprint.c index 39e09da..39c8ce2 100644 --- a/src/keyprint.c +++ b/src/keyprint.c @@ -162,7 +162,7 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) { byte *hash = pcppubkey_getchecksum(key); fprintf(out, " Checksum: "); - int i; + size_t i; for ( i = 0;i <15 ;++i) fprintf(out, "%02X:",(unsigned int) hash[i]); fprintf(out, "%02X", hash[15]); fprintf(out, "\n "); @@ -174,7 +174,8 @@ void pcppubkey_print(pcp_pubkey_t *key, FILE* out) { char *r = pcppubkey_get_art(key); fprintf(out, " Random Art ID: "); - for (i=0; iid); printf(" Owner: %s\n", key->owner); char *r = pcpkey_get_art(key); printf(" Random Art ID: "); - for (i=0; iid); printf(" Owner: %s\n", key->owner); char *r = pcppubkey_get_art(key); printf(" Random Art ID: "); - for (i=0; i