[opentyrian] 05/06: check return value in efread/efwrite
Etienne Millon
emillon-guest at moszumanska.debian.org
Mon Jan 5 15:09:03 UTC 2015
This is an automated email from the git hooks/post-receive script.
emillon-guest pushed a commit to branch master
in repository opentyrian.
commit 17f9324a8bf8e61d705527a04a8f21971cf465d0
Author: Etienne Millon <me at emillon.org>
Date: Mon Jan 5 15:45:28 2015 +0100
check return value in efread/efwrite
---
debian/patches/check-return-values.patch | 98 +++++++++++++++++++++++++++-----
1 file changed, 84 insertions(+), 14 deletions(-)
diff --git a/debian/patches/check-return-values.patch b/debian/patches/check-return-values.patch
index 7772e94..6941c69 100644
--- a/debian/patches/check-return-values.patch
+++ b/debian/patches/check-return-values.patch
@@ -1,19 +1,89 @@
---- a/src/lvllib.c
-+++ b/src/lvllib.c
-@@ -29,10 +29,13 @@
+Author: Etienne Millon <me at emillon.org>
+Subject: Check return values
+
+Make efread/efwrite check their return values.
+This can be done with an assert() since the actual return value is not used.
+
+--- a/src/file.c
++++ b/src/file.c
+@@ -21,6 +21,7 @@
+
+ #include "SDL.h"
+ #include <errno.h>
++#include <assert.h>
+
+ const char *custom_data_dir = ".";
+
+@@ -123,12 +124,12 @@
+ return size;
+ }
+
+-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ // endian-swapping fread
+-size_t efread( void *buffer, size_t size, size_t num, FILE *stream )
++void efread( void *buffer, size_t size, size_t num, FILE *stream )
{
- FILE *f = dir_fopen_die(data_dir(), levelFile, "rb");
+ size_t f = fread(buffer, size, num, stream);
-- efread(&lvlNum, sizeof(JE_word), 1, f);
-+ int res = efread(&lvlNum, sizeof(JE_word), 1, f);
-+ assert(res == 1);
++#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ switch (size)
+ {
+ case 2:
+@@ -146,15 +147,17 @@
+ default:
+ break;
+ }
+-
+- return f;
++#endif
++
++ assert(f == num);
+ }
+
+ // endian-swapping fwrite
+-size_t efwrite( void *buffer, size_t size, size_t num, FILE *stream )
++void efwrite( void *buffer, size_t size, size_t num, FILE *stream )
+ {
+ void *swap_buffer;
+
++#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ switch (size)
+ {
+ case 2:
+@@ -176,12 +179,16 @@
+ swap_buffer = buffer;
+ break;
+ }
++#else
++ swap_buffer = buffer;
++#endif
-- for (int x = 0; x < lvlNum; x++)
-- efread(&lvlPos[x], sizeof(JE_longint), 1, f);
-+ for (int x = 0; x < lvlNum; x++) {
-+ res = efread(&lvlPos[x], sizeof(JE_longint), 1, f);
-+ assert(res == 1);
-+ }
+ size_t f = fwrite(swap_buffer, size, num, stream);
- lvlPos[lvlNum] = ftell_eof(f);
++#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+ if (swap_buffer != buffer)
+ free(swap_buffer);
++#endif
+- return f;
++ assert(f == num);
+ }
+-#endif
+--- a/src/file.h
++++ b/src/file.h
+@@ -40,13 +40,8 @@
+ long ftell_eof( FILE *f );
+
+ // endian-swapping fread/fwrite
+-#if SDL_BYTEORDER == SDL_BIG_ENDIAN
+-size_t efread( void *buffer, size_t size, size_t num, FILE *stream );
+-size_t efwrite( void *buffer, size_t size, size_t num, FILE *stream );
+-#else
+-#define efread fread
+-#define efwrite fwrite
+-#endif
++void efread( void *buffer, size_t size, size_t num, FILE *stream );
++void efwrite( void *buffer, size_t size, size_t num, FILE *stream );
+
+ #endif // FILE_H
+
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/opentyrian.git
More information about the Pkg-games-commits
mailing list