From: Brian Paul Date: Fri, 5 May 2006 14:49:38 +0000 (+0000) Subject: check for float->uint overflow in _mesa_unpack_depth_span() X-Git-Tag: mesa-7.8~7596 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9b20b68af16af6bd630e9a5ed5b56fdf837fa29f;p=platform%2Fupstream%2Fmesa.git check for float->uint overflow in _mesa_unpack_depth_span() --- diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index a82b540..fbc7147 100644 --- a/src/mesa/main/image.c +++ b/src/mesa/main/image.c @@ -1,6 +1,6 @@ /* * Mesa 3-D graphics library - * Version: 6.5 + * Version: 6.5.1 * * Copyright (C) 1999-2006 Brian Paul All Rights Reserved. * @@ -3953,8 +3953,21 @@ _mesa_unpack_depth_span( const GLcontext *ctx, GLuint n, if (dstType == GL_UNSIGNED_INT) { GLuint *zValues = (GLuint *) dest; GLuint i; - for (i = 0; i < n; i++) { - zValues[i] = (GLuint) (depthValues[i] * depthScale); + if (depthScale <= (GLfloat) 0xffffff) { + /* no overflow worries */ + for (i = 0; i < n; i++) { + zValues[i] = (GLuint) (depthValues[i] * depthScale); + } + } + else { + /* need to use double precision to prevent overflow problems */ + for (i = 0; i < n; i++) { + GLdouble z = depthValues[i] * depthScale; + if (z >= (GLdouble) 0xffffffff) + zValues[i] = 0xffffffff; + else + zValues[i] = (GLuint) z; + } } } else if (dstType == GL_UNSIGNED_SHORT) {