From 4de778c4e7bb5b6b918f10c45b888d42387f8aec Mon Sep 17 00:00:00 2001 From: Bill Somerville Date: Tue, 15 Mar 2016 11:46:26 +0000 Subject: [PATCH] Reverting r6531 and replacing with correct fix The WSPR message is unpacked into a symbol per byte array which is processed by encoding a whole number of bytes of message, this requires the output array to be bigger than the number of symbols to accommodate extra values that are not part of the message due to rounding up to whole bytes. I.e. 176 (11*8*2) elements to contain the 162 symbols. git-svn-id: svn+ssh://svn.code.sf.net/p/wsjt/wsjt/branches/wsjtx@6532 ab8295b8-cf94-4d9e-aec4-7959e3be5d79 --- lib/wsprd/fano.c | 4 ++-- lib/wsprd/wsprsim_utils.c | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/wsprd/fano.c b/lib/wsprd/fano.c index bf2603a45..8fe1a649e 100644 --- a/lib/wsprd/fano.c +++ b/lib/wsprd/fano.c @@ -60,7 +60,7 @@ struct node { * and easier than trying to pack them more compactly. */ int encode( - unsigned char *symbols, // Output buffer, 2*nbytes + unsigned char *symbols, // Output buffer, 2*nbytes*8 unsigned char *data, // Input buffer, nbytes unsigned int nbytes) // Number of bytes in data { @@ -69,7 +69,7 @@ int encode( int i; encstate = 0; - while(--nbytes != 0) { + while(nbytes-- != 0) { for(i=7;i>=0;i--) { encstate = (encstate << 1) | ((*data >> i) & 1); ENCODE(sym,encstate); diff --git a/lib/wsprd/wsprsim_utils.c b/lib/wsprd/wsprsim_utils.c index a42b1cfa7..49a118c03 100644 --- a/lib/wsprd/wsprsim_utils.c +++ b/lib/wsprd/wsprsim_utils.c @@ -296,10 +296,9 @@ int get_wspr_channel_symbols(char* rawmessage, char* hashtab, unsigned char* sym unpk_(check_data,hashtab,check_call_loc_pow,check_callsign); // printf("Will decode as: %s\n",check_call_loc_pow); - unsigned int nbytes=11; // The message with tail is packed into 11 bytes. - unsigned int nencoded=162; - unsigned char channelbits[nencoded]; - memset(channelbits,0,sizeof(char)*nencoded); + unsigned int nbytes=11; // The message with tail is packed into almost 11 bytes. + unsigned char channelbits[nbytes*8*2]; /* 162 rounded up */ + memset(channelbits,0,sizeof channelbits); encode(channelbits,data,nbytes);