summaryrefslogtreecommitdiffstats
path: root/rbutil/sansapatcher
diff options
context:
space:
mode:
authorDave Chapman <dave@dchapman.com>2007-07-29 21:47:05 +0000
committerDave Chapman <dave@dchapman.com>2007-07-29 21:47:05 +0000
commitf119dc0d8202f8a000153fcf3558d336f2ff5c30 (patch)
tree28cb941b0ed37ee8976d76d25cc72ca48bf3c797 /rbutil/sansapatcher
parent33bc6f3e3c8c67a43b6dc9ce7cc92405c016b187 (diff)
downloadrockbox-f119dc0d8202f8a000153fcf3558d336f2ff5c30.tar.gz
rockbox-f119dc0d8202f8a000153fcf3558d336f2ff5c30.tar.bz2
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
Diffstat (limited to 'rbutil/sansapatcher')
-rw-r--r--rbutil/sansapatcher/Makefile2
-rw-r--r--rbutil/sansapatcher/sansapatcher.c26
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 @@
-CFLAGS=-Wall -D_LARGEFILE64_SOURCE
+CFLAGS=-Wall -W -D_LARGEFILE64_SOURCE
ifeq ($(findstring CYGWIN,$(shell uname)),CYGWIN)
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) {
#define MAX_SECTOR_SIZE 2048
#define SECTOR_SIZE 512
-int static inline le2int(unsigned char* buf)
+static inline int32_t le2int(unsigned char* buf)
{
int32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
return res;
}
-void static inline int2le(unsigned int val, unsigned char* addr)
+static inline uint32_t le2uint(unsigned char* buf)
+{
+ uint32_t res = (buf[3] << 24) | (buf[2] << 16) | (buf[1] << 8) | buf[0];
+
+ return res;
+}
+
+static inline void int2le(unsigned int val, unsigned char* addr)
{
addr[0] = val & 0xFF;
addr[1] = (val >> 8) & 0xff;
@@ -223,7 +230,7 @@ void tea_decrypt(uint32_t* v0, uint32_t* v1, uint32_t* k) {
void tea_decrypt_buf(unsigned char* src, unsigned char* dest, size_t n, uint32_t * key)
{
uint32_t v0, v1;
- int i;
+ unsigned int i;
for (i = 0; i < (n / 8); i++) {
v0 = le2int(src);
@@ -503,7 +510,7 @@ static int load_original_firmware(struct sansa_t* sansa, unsigned char* buf, str
tmpbuf,
mi4header->mi4size-(mi4header->plaintext+0x200),
keys[i]);
- key_found = (le2int(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55);
+ key_found = (le2uint(tmpbuf+mi4header->length-mi4header->plaintext-4) == 0xaa55aa55);
}
if (key_found) {
@@ -547,7 +554,11 @@ int sansa_read_firmware(struct sansa_t* sansa, char* filename)
return -1;
}
- write(outfile,sectorbuf,mi4header.mi4size);
+ res = write(outfile,sectorbuf,mi4header.mi4size);
+ if (res != (int)mi4header.mi4size) {
+ fprintf(stderr,"[ERR] Write error - %d\n", res);
+ return -1;
+ }
close(outfile);
return 0;
@@ -557,8 +568,8 @@ int sansa_read_firmware(struct sansa_t* sansa, char* filename)
int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type)
{
int res;
- int infile;
- int bl_length;
+ int infile = -1; /* Prevent an erroneous "may be used uninitialised" gcc warning */
+ int bl_length = 0; /* Keep gcc happy when building for rbutil */
struct mi4header_t mi4header;
int n;
int length;
@@ -587,6 +598,7 @@ int sansa_add_bootloader(struct sansa_t* sansa, char* filename, int type)
if (type==FILETYPE_MI4) {
/* Read bootloader into sectorbuf+0x200 */
n = read(infile,sectorbuf+0x200,bl_length);
+ close(infile);
if (n < bl_length) {
fprintf(stderr,"[ERR] Short read - requested %d bytes, received %d\n"
,bl_length,n);