Skip to content

Commit

Permalink
Fix issue 8639 dmd buffer overflow related to function literal, real.…
Browse files Browse the repository at this point in the history
…max, template alias parameter

The buffer for float conversion wasn't quite big enough!!
  • Loading branch information
don-clugston-sociomantic committed Nov 8, 2012
1 parent 842eeee commit ba044ed
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 @@ -2429,8 +2429,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 @@ -109,6 +109,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 ba044ed

Please sign in to comment.