From: Ondrej Lehecka Date: Wed, 29 Mar 2017 01:58:12 +0000 (-0700) Subject: Cursor::read() initializes return value X-Git-Tag: v2017.04.03.00~13 X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=cf6ef289c712ccd021fd9d66dc4cc509fc13c725;p=folly.git Cursor::read() initializes return value Summary: If the compiler doesn't see thru the call to tryRead which always initializes the val variable, it will emit the following error. I was getting error when compiling my android project: error: 'val' may be used uninitialized in this function [-Werror=maybe-uninitialized] This should not have a negative perf impact as smart compilers which inline call to tryRead can elliminate the initialization. Reviewed By: djwatson Differential Revision: D4790864 fbshipit-source-id: f353cfe54ca4d056b6ddfc075d00580c9f2d391e --- diff --git a/folly/io/Cursor.h b/folly/io/Cursor.h index 516b1039..5a8a32a6 100644 --- a/folly/io/Cursor.h +++ b/folly/io/Cursor.h @@ -227,7 +227,7 @@ class CursorBase { template T read() { - T val; + T val{}; if (!tryRead(val)) { std::__throw_out_of_range("underflow"); }