Skip to content

Commit

Permalink
cast values passed to isdigit to int instead of unsigned char
Browse files Browse the repository at this point in the history
  • Loading branch information
Chad Trabant committed Mar 4, 2015
1 parent 06772ce commit e60ab64
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 35 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
2015.062: 2.14
- Fix memory leak when msr_pack() returns after an error. Patch
contributed by Larry Baker and Eric Thomas.
- Change casting of values passed to isdigit() to int intead of
unsigned character. Apparently this was consufing on ARM archs.

2015.061:
- Add ms_readleapseconds() and ms_readleapsecondfile() routines to
Expand Down
65 changes: 33 additions & 32 deletions libmseed.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,18 +107,18 @@ extern "C" {
* Usage:
* MS_ISVALIDHEADER ((char *)X) X buffer must contain at least 27 bytes
*/
#define MS_ISVALIDHEADER(X) ( \
(isdigit ((unsigned char) *(X)) || *(X) == ' ' || !*(X) ) && \
(isdigit ((unsigned char) *(X+1)) || *(X+1) == ' ' || !*(X+1) ) && \
(isdigit ((unsigned char) *(X+2)) || *(X+2) == ' ' || !*(X+2) ) && \
(isdigit ((unsigned char) *(X+3)) || *(X+3) == ' ' || !*(X+3) ) && \
(isdigit ((unsigned char) *(X+4)) || *(X+4) == ' ' || !*(X+4) ) && \
(isdigit ((unsigned char) *(X+5)) || *(X+5) == ' ' || !*(X+5) ) && \
MS_ISDATAINDICATOR(*(X+6)) && \
(*(X+7) == ' ' || *(X+7) == '\0') && \
(int)(*(X+24)) >= 0 && (int)(*(X+24)) <= 23 && \
(int)(*(X+25)) >= 0 && (int)(*(X+25)) <= 59 && \
(int)(*(X+26)) >= 0 && (int)(*(X+26)) <= 60)
#define MS_ISVALIDHEADER(X) ( \
(isdigit ((int) *(X)) || *(X) == ' ' || !*(X) ) && \
(isdigit ((int) *(X+1)) || *(X+1) == ' ' || !*(X+1) ) && \
(isdigit ((int) *(X+2)) || *(X+2) == ' ' || !*(X+2) ) && \
(isdigit ((int) *(X+3)) || *(X+3) == ' ' || !*(X+3) ) && \
(isdigit ((int) *(X+4)) || *(X+4) == ' ' || !*(X+4) ) && \
(isdigit ((int) *(X+5)) || *(X+5) == ' ' || !*(X+5) ) && \
MS_ISDATAINDICATOR(*(X+6)) && \
(*(X+7) == ' ' || *(X+7) == '\0') && \
(int)(*(X+24)) >= 0 && (int)(*(X+24)) <= 23 && \
(int)(*(X+25)) >= 0 && (int)(*(X+25)) <= 59 && \
(int)(*(X+26)) >= 0 && (int)(*(X+26)) <= 60 )

/* Macro to test memory for a blank/noise SEED data record signature
* by checking for a valid SEED sequence number and padding characters
Expand All @@ -131,26 +131,27 @@ extern "C" {
* Usage:
* MS_ISVALIDBLANK ((char *)X) X buffer must contain at least 27 bytes
*/
#define MS_ISVALIDBLANK(X) ((isdigit ((unsigned char) *(X)) || !*(X) ) && \
(isdigit ((unsigned char) *(X+1)) || !*(X+1) ) && \
(isdigit ((unsigned char) *(X+2)) || !*(X+2) ) && \
(isdigit ((unsigned char) *(X+3)) || !*(X+3) ) && \
(isdigit ((unsigned char) *(X+4)) || !*(X+4) ) && \
(isdigit ((unsigned char) *(X+5)) || !*(X+5) ) && \
(*(X+6)==' ')&&(*(X+7)==' ')&&(*(X+8)==' ') && \
(*(X+9)==' ')&&(*(X+10)==' ')&&(*(X+11)==' ') && \
(*(X+12)==' ')&&(*(X+13)==' ')&&(*(X+14)==' ') && \
(*(X+15)==' ')&&(*(X+16)==' ')&&(*(X+17)==' ') && \
(*(X+18)==' ')&&(*(X+19)==' ')&&(*(X+20)==' ') && \
(*(X+21)==' ')&&(*(X+22)==' ')&&(*(X+23)==' ') && \
(*(X+24)==' ')&&(*(X+25)==' ')&&(*(X+26)==' ') && \
(*(X+27)==' ')&&(*(X+28)==' ')&&(*(X+29)==' ') && \
(*(X+30)==' ')&&(*(X+31)==' ')&&(*(X+32)==' ') && \
(*(X+33)==' ')&&(*(X+34)==' ')&&(*(X+35)==' ') && \
(*(X+36)==' ')&&(*(X+37)==' ')&&(*(X+38)==' ') && \
(*(X+39)==' ')&&(*(X+40)==' ')&&(*(X+41)==' ') && \
(*(X+42)==' ')&&(*(X+43)==' ')&&(*(X+44)==' ') && \
(*(X+45)==' ')&&(*(X+46)==' ')&&(*(X+47)==' ') )
#define MS_ISVALIDBLANK(X) ( \
(isdigit ((int) *(X)) || !*(X) ) && \
(isdigit ((int) *(X+1)) || !*(X+1) ) && \
(isdigit ((int) *(X+2)) || !*(X+2) ) && \
(isdigit ((int) *(X+3)) || !*(X+3) ) && \
(isdigit ((int) *(X+4)) || !*(X+4) ) && \
(isdigit ((int) *(X+5)) || !*(X+5) ) && \
(*(X+6) ==' ') && (*(X+7) ==' ') && (*(X+8) ==' ') && \
(*(X+9) ==' ') && (*(X+10)==' ') && (*(X+11)==' ') && \
(*(X+12)==' ') && (*(X+13)==' ') && (*(X+14)==' ') && \
(*(X+15)==' ') && (*(X+16)==' ') && (*(X+17)==' ') && \
(*(X+18)==' ') && (*(X+19)==' ') && (*(X+20)==' ') && \
(*(X+21)==' ') && (*(X+22)==' ') && (*(X+23)==' ') && \
(*(X+24)==' ') && (*(X+25)==' ') && (*(X+26)==' ') && \
(*(X+27)==' ') && (*(X+28)==' ') && (*(X+29)==' ') && \
(*(X+30)==' ') && (*(X+31)==' ') && (*(X+32)==' ') && \
(*(X+33)==' ') && (*(X+34)==' ') && (*(X+35)==' ') && \
(*(X+36)==' ') && (*(X+37)==' ') && (*(X+38)==' ') && \
(*(X+39)==' ') && (*(X+40)==' ') && (*(X+41)==' ') && \
(*(X+42)==' ') && (*(X+43)==' ') && (*(X+44)==' ') && \
(*(X+45)==' ') && (*(X+46)==' ') && (*(X+47)==' ') )

/* A simple bitwise AND test to return 0 or 1 */
#define bit(x,y) (x&y)?1:0
Expand Down
6 changes: 3 additions & 3 deletions parseutils.c
Original file line number Diff line number Diff line change
Expand Up @@ -411,9 +411,9 @@ ms_parse_raw ( char *record, int maxreclen, flag details, flag swapflag )
X = record; /* Pointer of convenience */

/* Check record sequence number, 6 ASCII digits */
if ( ! isdigit((unsigned char) *(X)) || ! isdigit ((unsigned char) *(X+1)) ||
! isdigit((unsigned char) *(X+2)) || ! isdigit ((unsigned char) *(X+3)) ||
! isdigit((unsigned char) *(X+4)) || ! isdigit ((unsigned char) *(X+5)) )
if ( ! isdigit((int) *(X)) || ! isdigit ((int) *(X+1)) ||
! isdigit((int) *(X+2)) || ! isdigit ((int) *(X+3)) ||
! isdigit((int) *(X+4)) || ! isdigit ((int) *(X+5)) )
{
ms_log (2, "%s: Invalid sequence number: '%c%c%c%c%c%c'\n", srcname, X, X+1, X+2, X+3, X+4, X+5);
retval++;
Expand Down

0 comments on commit e60ab64

Please sign in to comment.