To support this change, turn on lots more compiler warnings, and fix all the warnings generated.
Showing the changes to src/misc.c (1 of 93 files). Show all
Unified · Split
| @@ -15,6 +15,7 @@ · 14 unmodified lines | |||
| 15 | #include <math.h> | 15 | #include <math.h> |
| 16 | #include <stdio.h> | 16 | #include <stdio.h> |
| 17 | #include <stdlib.h> | 17 | #include <stdlib.h> |
| 18 | #include <stddef.h> | ||
| 18 | #include <time.h> | 19 | #include <time.h> |
| 19 | #include <string.h> | 20 | #include <string.h> |
| 20 | #include <ctype.h> | 21 | #include <ctype.h> |
| @@ -83,16 +84,16 @@ static const char writerr[] = "Error writing sample file. You are probably out · 62 unmodified lines | |||
| 83 | * Returns number of elements read, not bytes read. | 84 | * Returns number of elements read, not bytes read. |
| 84 | */ | 85 | */ |
| 85 | 86 | ||
| 86 | st_ssize_t st_readbuf(ft_t ft, void *buf, size_t size, st_size_t len) | 87 | size_t st_readbuf(ft_t ft, void *buf, size_t size, st_size_t len) |
| 87 | { | 88 | { |
| 88 | return fread(buf, size, len, ft->fp); | 89 | return fread(buf, size, len, ft->fp); |
| 89 | } | 90 | } |
| 90 | 91 | ||
| 91 | /* Write a buffer of data of length len and each element is size bytes. | 92 | /* Write a buffer of data of length len and each element is size bytes. |
| 92 | * Returns number of elements writen, not bytes writen. | 93 | * Returns number of elements writen, not bytes written. |
| 93 | */ | 94 | */ |
| 94 | 95 | ||
| 95 | st_ssize_t st_writebuf(ft_t ft, void const *buf, size_t size, st_size_t len) | 96 | size_t st_writebuf(ft_t ft, void const *buf, size_t size, st_size_t len) |
| 96 | { | 97 | { |
| 97 | return fwrite(buf, size, len, ft->fp); | 98 | return fwrite(buf, size, len, ft->fp); |
| 98 | } | 99 | } |
| @@ -157,13 +158,11 @@ int st_reads(ft_t ft, char *c, st_size_t len) · 58 unmodified lines | |||
| 157 | return (ST_EOF); | 158 | return (ST_EOF); |
| 158 | } | 159 | } |
| 159 | if (in == 0 || in == '\n') | 160 | if (in == 0 || in == '\n') |
| 160 | { | ||
| 161 | break; | 161 | break; |
| 162 | } | ||
| 163 | 162 | ||
| 164 | *sc = in; | 163 | *sc = in; |
| 165 | sc++; | 164 | sc++; |
| 166 | } while (sc - c < len); | 165 | } while (sc - c < (ptrdiff_t)len); |
| 167 | *sc = 0; | 166 | *sc = 0; |
| 168 | return(ST_SUCCESS); | 167 | return(ST_SUCCESS); |
| 169 | } | 168 | } |
| @@ -306,7 +305,7 @@ int st_writedf(ft_t ft, double d) · 136 unmodified lines | |||
| 306 | } | 305 | } |
| 307 | 306 | ||
| 308 | /* generic swap routine. Swap l and place in to f (datatype length = n) */ | 307 | /* generic swap routine. Swap l and place in to f (datatype length = n) */ |
| 309 | void st_swapb(char *l, char *f, int n) | 308 | static void st_swapb(char *l, char *f, int n) |
| 310 | { | 309 | { |
| 311 | register int i; | 310 | register int i; |
| 312 | 311 | ||
| @@ -358,18 +357,28 @@ double st_swapd(double df) · 45 unmodified lines | |||
| 358 | 357 | ||
| 359 | 358 | ||
| 360 | /* dummy format routines for do-nothing functions */ | 359 | /* dummy format routines for do-nothing functions */ |
| 361 | int st_format_nothing(ft_t ft) { return(ST_SUCCESS); } | 360 | int st_format_nothing(ft_t ft UNUSED) { return(ST_SUCCESS); } |
| 362 | st_ssize_t st_format_nothing_read_io(ft_t ft, st_sample_t *buf, st_size_t len) { return(0); } | 361 | st_size_t st_format_nothing_read_io(ft_t ft UNUSED, st_sample_t *buf UNUSED, st_size_t len UNUSED) { return(0); } |
| 363 | st_ssize_t st_format_nothing_write_io(ft_t ft, const st_sample_t *buf, st_size_t len) { return(0); } | 362 | st_size_t st_format_nothing_write_io(ft_t ft UNUSED, const st_sample_t *buf UNUSED, st_size_t len UNUSED) { return(0); } |
| 364 | int st_format_nothing_seek(ft_t ft, st_size_t offset) { st_fail_errno(ft, ST_ENOTSUP, "operation not supported"); return(ST_EOF); } | 363 | int st_format_nothing_seek(ft_t ft UNUSED, st_size_t offset UNUSED) { st_fail_errno(ft, ST_ENOTSUP, "operation not supported"); return(ST_EOF); } |
| 365 | 364 | ||
| 366 | /* dummy effect routine for do-nothing functions */ | 365 | /* dummy effect routine for do-nothing functions */ |
| 367 | int st_effect_nothing(eff_t effp) { return(ST_SUCCESS); } | 366 | int st_effect_nothing(eff_t effp UNUSED) { return(ST_SUCCESS); } |
| 368 | int st_effect_nothing_drain(eff_t effp, st_sample_t *obuf, st_size_t *osamp) | 367 | int st_effect_nothing_drain(eff_t effp UNUSED, st_sample_t *obuf UNUSED, st_size_t *osamp) |
| 369 | { /* Inform no more samples to drain */ *osamp = 0; return(ST_EOF); } | 368 | { /* Inform no more samples to drain */ *osamp = 0; return(ST_EOF); } |
| 370 | 369 | ||
| 370 | int st_effect_nothing_getopts(eff_t effp, int n, char **argv UNUSED) | ||
| 371 | { | ||
| 372 | if (n) { | ||
| 373 | st_fail(effp->h->usage); | ||
| 374 | return (ST_EOF); | ||
| 375 | } | ||
| 376 | return (ST_SUCCESS); | ||
| 377 | } | ||
| 378 | |||
| 379 | |||
| 371 | /* here for linear interp. might be useful for other things */ | 380 | /* here for linear interp. might be useful for other things */ |
| 372 | st_sample_t st_gcd(st_sample_t a, st_sample_t b) | 381 | REGPARM(2) st_sample_t st_gcd(st_sample_t a, st_sample_t b) |
| 373 | { | 382 | { |
| 374 | if (b == 0) | 383 | if (b == 0) |
| 375 | return a; | 384 | return a; |
| @@ -377,7 +386,7 @@ st_sample_t st_gcd(st_sample_t a, st_sample_t b) · 1 unmodified line | |||
| 377 | return st_gcd(b, a % b); | 386 | return st_gcd(b, a % b); |
| 378 | } | 387 | } |
| 379 | 388 | ||
| 380 | st_sample_t st_lcm(st_sample_t a, st_sample_t b) | 389 | REGPARM(2) st_sample_t st_lcm(st_sample_t a, st_sample_t b) |
| 381 | { | 390 | { |
| 382 | /* parenthesize this way to avoid st_sample_t overflow in product term */ | 391 | /* parenthesize this way to avoid st_sample_t overflow in product term */ |
| 383 | return a * (b / st_gcd(a, b)); | 392 | return a * (b / st_gcd(a, b)); |
| @@ -429,7 +438,7 @@ void st_initrand(void) { · 45 unmodified lines | |||
| 429 | void st_generate_wave_table( | 438 | void st_generate_wave_table( |
| 430 | st_wave_t wave_type, | 439 | st_wave_t wave_type, |
| 431 | st_data_t data_type, | 440 | st_data_t data_type, |
| 432 | void * table, | 441 | void *table, |
| 433 | uint32_t table_size, | 442 | uint32_t table_size, |
| 434 | double min, | 443 | double min, |
| 435 | double max, | 444 | double max, |
| @@ -457,19 +466,47 @@ void st_generate_wave_table( · 21 unmodified lines | |||
| 457 | case 3: d = d - 1.5; break; | 466 | case 3: d = d - 1.5; break; |
| 458 | } | 467 | } |
| 459 | break; | 468 | break; |
| 469 | |||
| 470 | default: /* Oops! FIXME */ | ||
| 471 | d = 0.0; /* Make sure we have a value */ | ||
| 472 | break; | ||
| 460 | } | 473 | } |
| 461 | d = d * (max - min) + min; | 474 | d = d * (max - min) + min; |
| 462 | switch (data_type) | 475 | switch (data_type) |
| 463 | { | 476 | { |
| 464 | case ST_FLOAT : *(float *)table = d; table += sizeof(float ); continue; | 477 | case ST_FLOAT: |
| 465 | case ST_DOUBLE: *(double *)table = d; table += sizeof(double); continue; | 478 | { |
| 479 | float *fp = (float *)table; | ||
| 480 | *fp++ = (float)d; | ||
| 481 | table = fp; | ||
| 482 | continue; | ||
| 483 | } | ||
| 484 | case ST_DOUBLE: | ||
| 485 | { | ||
| 486 | double *dp = (double *)table; | ||
| 487 | *dp++ = d; | ||
| 488 | table = dp; | ||
| 489 | continue; | ||
| 490 | } | ||
| 466 | default: break; | 491 | default: break; |
| 467 | } | 492 | } |
| 468 | d += d < 0? -0.5 : +0.5; | 493 | d += d < 0? -0.5 : +0.5; |
| 469 | switch (data_type) | 494 | switch (data_type) |
| 470 | { | 495 | { |
| 471 | case ST_SHORT : *(short *)table = d; table += sizeof(short ); continue; | 496 | case ST_SHORT: |
| 472 | case ST_INT : *(int *)table = d; table += sizeof(int ); continue; | 497 | { |
| 498 | short *sp = table; | ||
| 499 | *sp++ = (short)d; | ||
| 500 | table = sp; | ||
| 501 | continue; | ||
| 502 | } | ||
| 503 | case ST_INT: | ||
| 504 | { | ||
| 505 | int *ip = table; | ||
| 506 | *ip++ = (int)d; | ||
| 507 | table = ip; | ||
| 508 | continue; | ||
| 509 | } | ||
| 473 | default: break; | 510 | default: break; |
| 474 | } | 511 | } |
| 475 | } | 512 | } |
| @@ -542,5 +579,5 @@ enum_item const * find_enum_text(char const * text, enum_item const * enum_items · 66 unmodified lines | |||
| 542 | enum_item const st_wave_enum[] = { | 579 | enum_item const st_wave_enum[] = { |
| 543 | ENUM_ITEM(ST_WAVE_,SINE) | 580 | ENUM_ITEM(ST_WAVE_,SINE) |
| 544 | ENUM_ITEM(ST_WAVE_,TRIANGLE) | 581 | ENUM_ITEM(ST_WAVE_,TRIANGLE) |
| 545 | {0}}; | 582 | {0, 0}}; |
| 546 | 583 | ||