This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR libstdc++/87228 Use heap for large buffers instead of alloca


Using a huge width in a formatted output operation results in stack
overflow due to no restriction on the size passed to alloca. This patch
causes the formatting functions to use the heap instead of the stack
when a large buffer is needed.

	PR libstdc++/87228
	* include/bits/locale_facets.tcc (num_put:_M_insert_int): Use heap
	for large buffers instead of alloca.
	(num_put:_M_insert_float): Likewise.
	* testsuite/22_locale/num_put/put/char/87228.cc: New test.
	* testsuite/22_locale/num_put/put/wchar_t/87228.cc: New test.

Tested x86_64-linux.

Even with this patch we can still put 3kb on the stack, but that's
much better than trying (and failing) to use alloca for huge values.

An alternative would be to just check for silly values and throw
std::length_error, but I think this is the right fix.

I'll wait a day or two for any comments or better ideas.

Attachment: patch.txt
Description: Text document


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]