diff options
author | Dave Chapman <dave@dchapman.com> | 2007-07-29 21:47:05 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2007-07-29 21:47:05 +0000 |
commit | f119dc0d8202f8a000153fcf3558d336f2ff5c30 (patch) | |
tree | 28cb941b0ed37ee8976d76d25cc72ca48bf3c797 | |
parent | 33bc6f3e3c8c67a43b6dc9ce7cc92405c016b187 (diff) | |
download | rockbox-f119dc0d8202f8a000153fcf3558d336f2ff5c30.tar.gz rockbox-f119dc0d8202f8a000153fcf3558d336f2ff5c30.zip |
Add -W to CFLAGS in Makefile and fix generated warnings. Also close a file handle which was being left open
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@14069 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | rbutil/sansapatcher/Makefile | 2 | ||||
-rw-r--r-- | rbutil/sansapatcher/sansapatcher.c | 26 |
2 files changed, 20 insertions, 8 deletions
diff --git a/rbutil/sansapatcher/Makefile b/rbutil/sansapatcher/Makefile index 28ba1dae6a..b05d8f3257 100644 --- a/rbutil/sansapatcher/Makefile +++ b/rbutil/sansapatcher/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | CFLAGS=-Wall -D_LARGEFILE64_SOURCE | 1 | CFLAGS=-Wall -W -D_LARGEFILE64_SOURCE |
2 | 2 | ||
3 | ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) | 3 | ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN) |
4 | OUTPUT=sansapatcher.exe | 4 | OUTPUT=sansapatcher.exe |
diff --git a/rbutil/sansapatcher/sansapatcher.c b/rbutil/sansapatcher/sansapatcher.c index 3f25762a14..9b52196a7b 100644 --- a/rbutil/sansapatcher/sansapatcher.c +++ b/rbutil/sansapatcher/sansapatcher.c | |||
@@ -60,14 +60,21 @@ static off_t filesize(int fd) { | |||
60 | #define MAX_SECTOR_SIZE 2048 | 60 | #define MAX_SECTOR_SIZE 2048 |
61 | #define SECTOR_SIZE 512 | 61 | #define SECTOR_SIZE 512 |
62 | 62 | ||
63 | int static inline le2int(unsigned char* buf) | 63 | static inline int32_t le2int(unsigned char* buf) |
64 | { | 64 | { |
65 | int32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | 65 | int32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; |
66 | 66 | ||
67 | return res; | 67 | return res; |
68 | } | 68 | } |
69 | 69 | ||
70 | void static inline int2le(unsigned int val, unsigned char* addr) | 70 | static inline uint32_t le2uint(unsigned char* buf) |
71 | { | ||
72 | uint32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0]; | ||
73 | |||
74 | return res; | ||
75 | } | ||
76 | |||
77 | static inline void int2le(unsigned int val, unsigned char* addr) | ||
71 | { | 78 | { |
72 | addr[0] = val & 0xFF; | 79 | addr[0] = val & 0xFF; |
73 | addr[1] = (val >> 8) & 0xff; | 80 | addr[1] = (val >> 8) & 0xff; |
@@ -223,7 +230,7 @@ void tea_decrypt(uint32_t* v0, uint32_t* v1, uint32_t* k) { | |||
223 | void tea_decrypt_buf(unsigned char* src, unsigned char* dest, size_t n, uint32_t * key) | 230 | void tea_decrypt_buf(unsigned char* src, unsigned char* dest, size_t n, uint32_t * key) |
224 | { | 231 | { |
225 | uint32_t v0, v1; | 232 | uint32_t v0, v1; |
226 | int i; | 233 | unsigned int i; |
227 | 234 | ||
228 | for (i = 0; i < (n / 8); i++) { | 235 | for (i = 0; i < (n / 8); i++) { |
229 | v0 = le2int(src); | 236 | v0 = le2int(src); |
@@ -503,7 +510,7 @@ static int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, str | |||
503 | tmpbuf, | 510 | tmpbuf, |
504 | mi4header->mi4size-(mi4header->plaintext+0x200), | 511 | mi4header->mi4size-(mi4header->plaintext+0x200), |
505 | keys[i]); | 512 | keys[i]); |
506 | key_found = (le2int(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); | 513 | key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55); |
507 | } | 514 | } |
508 | 515 | ||
509 | if (key_found) { | 516 | if (key_found) { |
@@ -547,7 +554,11 @@ int sansa_read_firmware(struct sansa_t* sansa, char* filename) | |||
547 | return -1; | 554 | return -1; |
548 | } | 555 | } |
549 | 556 | ||
550 | write(outfile,sectorbuf,mi4header.mi4size); | 557 | res = write(outfile,sectorbuf,mi4header.mi4size); |
558 | if (res != (int)mi4header.mi4size) { | ||
559 | fprintf(stderr,"[ERR] Write error - %d\n", res); | ||
560 | return -1; | ||
561 | } | ||
551 | close(outfile); | 562 | close(outfile); |
552 | 563 | ||
553 | return 0; | 564 | return 0; |
@@ -557,8 +568,8 @@ int sansa_read_firmware(struct sansa_t* sansa, char* filename) | |||
557 | int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) | 568 | int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) |
558 | { | 569 | { |
559 | int res; | 570 | int res; |
560 | int infile; | 571 | int infile = -1; /* Prevent an erroneous "may be used uninitialised" gcc warning */ |
561 | int bl_length; | 572 | int bl_length = 0; /* Keep gcc happy when building for rbutil */ |
562 | struct mi4header_t mi4header; | 573 | struct mi4header_t mi4header; |
563 | int n; | 574 | int n; |
564 | int length; | 575 | int length; |
@@ -587,6 +598,7 @@ int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type) | |||
587 | if (type==FILETYPE_MI4) { | 598 | if (type==FILETYPE_MI4) { |
588 | /* Read bootloader into sectorbuf+0x200 */ | 599 | /* Read bootloader into sectorbuf+0x200 */ |
589 | n = read(infile,sectorbuf+0x200,bl_length); | 600 | n = read(infile,sectorbuf+0x200,bl_length); |
601 | close(infile); | ||
590 | if (n < bl_length) { | 602 | if (n < bl_length) { |
591 | fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n" | 603 | fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n" |
592 | ,bl_length,n); | 604 | ,bl_length,n); |