summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-05 08:58:30 +0000
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2010-06-05 08:58:30 +0000
commite49464b38735585eaa0ce01f5734c0bcfad851dd (patch)
tree6a5eed99d5bdad8ebc75fe5b9aeb7306a7418bd0
parent219f5db1dcd779f0373d1b97d3878df5b3ab801f (diff)
downloadrockbox-e49464b38735585eaa0ce01f5734c0bcfad851dd.tar.gz
rockbox-e49464b38735585eaa0ce01f5734c0bcfad851dd.tar.bz2
rockbox-e49464b38735585eaa0ce01f5734c0bcfad851dd.zip
Improve error handling.
Add some more return checks and fix a memleak on error. Addresses warnings when building with Rockbox Utility. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26569 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--tools/wavtrim.c18
1 files changed, 16 insertions, 2 deletions
diff --git a/tools/wavtrim.c b/tools/wavtrim.c
index 8517b4677e..36a1151b4d 100644
--- a/tools/wavtrim.c
+++ b/tools/wavtrim.c
@@ -198,12 +198,26 @@ int wavtrim(char * filename, int maxsilence ,char* errstring,int errsize)
if (pFile == NULL)
{
snprintf(errstring,errsize,"Error opening file %s for writing\n",filename);
+ free(pBuf);
return -1;
}
/* write the new file */
- fwrite(pBuf, 1, datapos, pFile); /* write header */
- fwrite(pBuf + datapos + skip_head, 1, datalen - skip_head - skip_tail, pFile);
+ if ((int)fwrite(pBuf, 1, datapos, pFile) != datapos) /* write header */
+ {
+ snprintf(errstring,errsize,"Error writing file %s header\n",filename);
+ fclose(pFile);
+ free(pBuf);
+ return -1;
+ }
+ if ((int)fwrite(pBuf + datapos + skip_head, 1, datalen - skip_head - skip_tail, pFile)
+ != datalen - skip_head - skip_tail)
+ {
+ snprintf(errstring,errsize,"Error writing file %s data\n",filename);
+ fclose(pFile);
+ free(pBuf);
+ return -1;
+ }
fclose(pFile);
free(pBuf);