[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[pygame] [PATCH] Fix integer overflow of FULLSCREEN constant (and possibly other constants)
Hi all,
I've run into the this bug today:
http://osdir.com/ml/python.pygame/2005-08/msg00136.html.
The problem is, SDL_video.h defines SDL_FULLSCREEN as 0x80000000, this
value is cast to int in constants.c, and an overflow occurs:
#define DEC_CONST(x) PyModule_AddIntConstant(module, #x, (int) SDL_##x);
<...>
DEC_CONST(FULLSCREEN);
Replacing (int) with (long) solves the problem, and long is exactly what
should be used there:
int PyModule_AddIntConstant(PyObject *module, const char *name, long value)
So here is a patch.
Thanks,
Andrey
diff -Naur pygame-1.8.0release.orig/src/constants.c pygame-1.8.0release/src/constants.c
--- pygame-1.8.0release.orig/src/constants.c 2008-02-14 00:48:58.000000000 +0500
+++ pygame-1.8.0release/src/constants.c 2008-05-17 00:49:11.000000000 +0600
@@ -24,10 +24,10 @@
#include "scrap.h"
/* macros used to create each constant */
-#define DEC_CONST(x) PyModule_AddIntConstant(module, #x, (int) SDL_##x);
-#define DEC_CONSTK(x) PyModule_AddIntConstant(module, #x, (int) SDL##x);
-#define DEC_CONSTN(x) PyModule_AddIntConstant(module, #x, (int) x);
-#define DEC_CONSTS(x,y) PyModule_AddIntConstant(module, #x, (int) y);
+#define DEC_CONST(x) PyModule_AddIntConstant(module, #x, (long) SDL_##x);
+#define DEC_CONSTK(x) PyModule_AddIntConstant(module, #x, (long) SDL##x);
+#define DEC_CONSTN(x) PyModule_AddIntConstant(module, #x, (long) x);
+#define DEC_CONSTS(x,y) PyModule_AddIntConstant(module, #x, (long) y);
#define ADD_STRING_CONST(x) PyModule_AddStringConstant(module, #x, x);