src/file/SDL_rwops.c
changeset 1078 e2ef6b7001fd
parent 769 b8d311d90021
child 1202 0748fbb272e7
--- a/src/file/SDL_rwops.c	Wed Jun 15 23:41:57 2005 +0000
+++ b/src/file/SDL_rwops.c	Fri Jun 24 12:48:38 2005 +0000
@@ -110,15 +110,23 @@
 }
 static int mem_read(SDL_RWops *context, void *ptr, int size, int maxnum)
 {
-	int num;
+	int total_bytes;
+	int mem_available;
+
+	total_bytes = (maxnum * size);
+	if ( (maxnum <= 0) || (size <= 0) || ((total_bytes / maxnum) != size) ) {
+		return 0;
+	}
 
-	num = maxnum;
-	if ( (context->hidden.mem.here + (num*size)) > context->hidden.mem.stop ) {
-		num = (context->hidden.mem.stop-context->hidden.mem.here)/size;
+	mem_available = (context->hidden.mem.stop - context->hidden.mem.here);
+	if (total_bytes > mem_available) {
+		total_bytes = mem_available;
 	}
-	memcpy(ptr, context->hidden.mem.here, num*size);
-	context->hidden.mem.here += num*size;
-	return(num);
+
+	memcpy(ptr, context->hidden.mem.here, total_bytes);
+	context->hidden.mem.here += total_bytes;
+
+	return (total_bytes / size);
 }
 static int mem_write(SDL_RWops *context, const void *ptr, int size, int num)
 {