From 9b20b68af16af6bd630e9a5ed5b56fdf837fa29f Mon Sep 17 00:00:00 2001 From: Brian Paul Date: Fri, 5 May 2006 14:49:38 +0000 Subject: check for float->uint overflow in _mesa_unpack_depth_span() --- src/mesa/main/image.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/mesa/main/image.c') diff --git a/src/mesa/main/image.c b/src/mesa/main/image.c index a82b540ed6..fbc7147f93 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) { -- cgit v1.2.3