From: John Kessenich Date: Wed, 19 Feb 2014 00:08:59 +0000 (+0000) Subject: Check-in a couple submitted char* string portability bug fixes: correct sizing of... X-Git-Tag: upstream/0.1~732 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6494baf37104d2b41635c96c3d2ca935ddb55c4c;p=platform%2Fupstream%2Fglslang.git Check-in a couple submitted char* string portability bug fixes: correct sizing of buffers and stop overwriting preprocessor token names with themselves. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@25402 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- diff --git a/StandAlone/StandAlone.cpp b/StandAlone/StandAlone.cpp index dd07657..05197c1 100644 --- a/StandAlone/StandAlone.cpp +++ b/StandAlone/StandAlone.cpp @@ -224,7 +224,7 @@ void ProcessConfigFile() } if (config == 0) { - config = new char[strlen(DefaultConfig)]; + config = new char[strlen(DefaultConfig) + 1]; strcpy(config, DefaultConfig); } @@ -862,10 +862,10 @@ char** ReadFileData(const char* fileName) { FILE *in; int errorCode = fopen_s(&in, fileName, "r"); - char* fdata; + char *fdata; int count = 0; const int maxSourceStrings = 5; - char** return_data = (char**)malloc(maxSourceStrings+1); + char** return_data = (char**)malloc(sizeof(char *) * (maxSourceStrings+1)); //return_data[MAX_SOURCE_STRINGS]=NULL; if (errorCode) { diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h index d95b2e6..df9fce1 100644 --- a/glslang/Include/revision.h +++ b/glslang/Include/revision.h @@ -9,5 +9,5 @@ // source have to figure out how to create revision.h just to get a build // going. However, if it is not updated, it can be a version behind. -#define GLSLANG_REVISION "25392" -#define GLSLANG_DATE "2014/02/18 14:55:42" +#define GLSLANG_REVISION "25400" +#define GLSLANG_DATE "2014/02/18 16:37:57" diff --git a/glslang/MachineIndependent/preprocessor/PpContext.h b/glslang/MachineIndependent/preprocessor/PpContext.h index 69edc2c..1c14dd0 100644 --- a/glslang/MachineIndependent/preprocessor/PpContext.h +++ b/glslang/MachineIndependent/preprocessor/PpContext.h @@ -381,7 +381,7 @@ protected: int InitScanner(TPpContext* cpp); int ScanFromString(char* s); void missingEndifCheck(); - int lFloatConst(char* str, int len, int ch, TPpToken* ppToken); + int lFloatConst(int len, int ch, TPpToken* ppToken); bool inComment; diff --git a/glslang/MachineIndependent/preprocessor/PpScanner.cpp b/glslang/MachineIndependent/preprocessor/PpScanner.cpp index 4e68f34..eedb478 100644 --- a/glslang/MachineIndependent/preprocessor/PpScanner.cpp +++ b/glslang/MachineIndependent/preprocessor/PpScanner.cpp @@ -113,7 +113,7 @@ int TPpContext::InitScanner(TPpContext *cpp) * letter 'e', or a precision ending (e.g., F or LF). */ -int TPpContext::lFloatConst(char* str, int len, int ch, TPpToken* ppToken) +int TPpContext::lFloatConst(int len, int ch, TPpToken* ppToken) { bool HasDecimalOrExponent = false; int declen, exp, ExpSign; @@ -124,6 +124,7 @@ int TPpContext::lFloatConst(char* str, int len, int ch, TPpToken* ppToken) exp = 0; str_len=len; + char* str = ppToken->name; if (ch == '.') { HasDecimalOrExponent = true; str[len++]=ch; @@ -220,8 +221,6 @@ int TPpContext::lFloatConst(char* str, int len, int ch, TPpToken* ppToken) ppToken->dval = strtod(str, 0); } - // Suffix: - strcpy(ppToken->name, str); if (isDouble) return CPP_DOUBLECONSTANT; @@ -385,7 +384,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) } while (ch >= '0' && ch <= '9'); } if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') - return pp->lFloatConst(ppToken->name, len, ch, ppToken); + return pp->lFloatConst(len, ch, ppToken); // wasn't a float, so must be octal... if (nonOctal) @@ -424,7 +423,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ch = pp->getChar(); } while (ch >= '0' && ch <= '9'); if (ch == '.' || ch == 'e' || ch == 'f' || ch == 'E' || ch == 'F' || ch == 'l' || ch == 'L') { - return pp->lFloatConst(ppToken->name, len, ch, ppToken); + return pp->lFloatConst(len, ch, ppToken); } else { // Finish handling signed and unsigned integers int numericLen = len; @@ -600,7 +599,7 @@ int TPpContext::tStringInput::scan(TPpToken* ppToken) ch = pp->getChar(); if (ch >= '0' && ch <= '9') { pp->ungetChar(); - return pp->lFloatConst(ppToken->name, 0, '.', ppToken); + return pp->lFloatConst(0, '.', ppToken); } else { pp->ungetChar(); return '.';