diff options
author | René Kijewski <rene.kijewski@fu-berlin.de> | 2023-03-27 05:10:14 +0200 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2023-03-31 13:02:03 +0200 |
commit | 41b4181a2001f5b6297a870e2875dc72e09b1989 (patch) | |
tree | c5fb413f247559b6d9ea4d1570d5063ead438c1a /testing/templates | |
parent | 795554e84ad923ae249d22c6145b194678ff7d89 (diff) | |
download | askama-41b4181a2001f5b6297a870e2875dc72e09b1989.tar.gz askama-41b4181a2001f5b6297a870e2875dc72e09b1989.tar.bz2 askama-41b4181a2001f5b6297a870e2875dc72e09b1989.zip |
Use `try_reserve()` instead of `with_capacity()`
`String::with_capacity()` panics if the requested memory could not be
allocated. `Template::render()` is fallible method, and the fact that it
can panic is not documented.
This commit uses `String::try_reserve()` instead, so even for an
exceedingly large `SIZE_HINT` the method should not panic. In the
generated code `write!()` calls will fail instead with
`Err(std::fmt::Error)`.
I do not test if `try_reserve()` returned an error, because the
rendering might succeed anyway, if less bytes are written than estimated.
Diffstat (limited to 'testing/templates')
0 files changed, 0 insertions, 0 deletions