Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files

Fix bug 122 - SDL_RWops bug fixes: set RWops.type field, add input va…

…lidation, add test coverage
  • Loading branch information
ferzkopp committed Mar 13, 2013
1 parent 46d44be commit aa6ce542099fac7ccadbd39de254e834927fb5bc
Showing with 215 additions and 14 deletions.
  1. +8 −0 include/SDL_rwops.h
  2. +24 −2 src/file/SDL_rwops.c
  3. +183 −12 test/testautomation_rwops.c
@@ -40,6 +40,14 @@ extern "C" {
/* *INDENT-ON* */
#endif

/* RWops Types */
#define SDL_RWOPS_UNKNOWN 0 /* Unknown stream type */
#define SDL_RWOPS_WINFILE 1 /* Win32 file */
#define SDL_RWOPS_STDFILE 2 /* Stdio file */
#define SDL_RWOPS_JNIFILE 3 /* Android asset */
#define SDL_RWOPS_MEMORY 4 /* Memory stream */
#define SDL_RWOPS_MEMORY_RO 5 /* Read-Only memory stream */

/**
* This is the read/write operation structure -- very basic.
*/
@@ -513,6 +513,7 @@ SDL_RWFromFile(const char *file, const char *mode)
rwops->read = Android_JNI_FileRead;
rwops->write = Android_JNI_FileWrite;
rwops->close = Android_JNI_FileClose;
rwops->type = SDL_RWOPS_JNIFILE;

#elif defined(__WIN32__)
rwops = SDL_AllocRW();
@@ -527,6 +528,7 @@ SDL_RWFromFile(const char *file, const char *mode)
rwops->read = windows_file_read;
rwops->write = windows_file_write;
rwops->close = windows_file_close;
rwops->type = SDL_RWOPS_WINFILE;

#elif HAVE_STDIO_H
{
@@ -570,6 +572,7 @@ SDL_RWFromFP(FILE * fp, SDL_bool autoclose)
rwops->close = stdio_close;
rwops->hidden.stdio.fp = fp;
rwops->hidden.stdio.autoclose = autoclose;
rwops->type = SDL_RWOPS_STDFILE;
}
return (rwops);
}
@@ -585,7 +588,15 @@ SDL_RWFromFP(void * fp, SDL_bool autoclose)
SDL_RWops *
SDL_RWFromMem(void *mem, int size)
{
SDL_RWops *rwops;
SDL_RWops *rwops = NULL;
if (!mem) {
SDL_InvalidParamError("mem");
return (rwops);
}
if (!size) {
SDL_InvalidParamError("size");
return (rwops);
}

rwops = SDL_AllocRW();
if (rwops != NULL) {
@@ -597,14 +608,23 @@ SDL_RWFromMem(void *mem, int size)
rwops->hidden.mem.base = (Uint8 *) mem;
rwops->hidden.mem.here = rwops->hidden.mem.base;
rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
rwops->type = SDL_RWOPS_MEMORY;
}
return (rwops);
}

SDL_RWops *
SDL_RWFromConstMem(const void *mem, int size)
{
SDL_RWops *rwops;
SDL_RWops *rwops = NULL;
if (!mem) {
SDL_InvalidParamError("mem");
return (rwops);
}
if (!size) {
SDL_InvalidParamError("size");
return (rwops);
}

rwops = SDL_AllocRW();
if (rwops != NULL) {
@@ -616,6 +636,7 @@ SDL_RWFromConstMem(const void *mem, int size)
rwops->hidden.mem.base = (Uint8 *) mem;
rwops->hidden.mem.here = rwops->hidden.mem.base;
rwops->hidden.mem.stop = rwops->hidden.mem.base + size;
rwops->type = SDL_RWOPS_MEMORY_RO;
}
return (rwops);
}
@@ -629,6 +650,7 @@ SDL_AllocRW(void)
if (area == NULL) {
SDL_OutOfMemory();
}
area->type = SDL_RWOPS_UNKNOWN;
return (area);
}

0 comments on commit aa6ce54

Please sign in to comment.