Skip to content

Commit

Permalink
Merge pull request #1270 from donc/regression8639realmax
Browse files Browse the repository at this point in the history
8639 dmd buffer overflow related to function literal, real.max template alias parameter
  • Loading branch information
braddr committed Nov 8, 2012
2 parents 7d39d57 + ba044ed commit 0d432ac
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/expression.c
Expand Up @@ -2498,8 +2498,11 @@ void floatToBuffer(OutBuffer *buf, Type *type, real_t value)
* to decimal then back again. If it matches, use it.
* If it doesn't, fall back to hex, which is
* always exact.
* Longest string is for -real.max:
* "-1.18973e+4932\0".length == 17
* "-0xf.fffffffffffffffp+16380\0".length == 28
*/
char buffer[25];
char buffer[32];
ld_sprint(buffer, 'g', value);
assert(strlen(buffer) < sizeof(buffer));
#if _WIN32 && __DMC__
Expand Down
9 changes: 9 additions & 0 deletions test/compilable/compile1.d
Expand Up @@ -147,6 +147,15 @@ static assert( !is(typeof( (){
undefined ~= delegate(){}; return 7;
}())));

/**************************************************
8639 Buffer overflow
**************************************************/

void t8639(alias a)() {}
void bug8639() {
t8639!({auto r = -real.max;})();
}

/**************************************************
7751 Segfault
**************************************************/
Expand Down

0 comments on commit 0d432ac

Please sign in to comment.