Cursor::read<T>() initializes return value
authorOndrej Lehecka <lehecka@fb.com>
Wed, 29 Mar 2017 01:58:12 +0000 (18:58 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Wed, 29 Mar 2017 02:12:52 +0000 (19:12 -0700)
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

folly/io/Cursor.h

index 516b10393be3dae1c050651676584706d5a36e57..5a8a32a606eab577c6602b16f848c904097c4c9a 100644 (file)
@@ -227,7 +227,7 @@ class CursorBase {
 
   template <class T>
   T read() {
 
   template <class T>
   T read() {
-    T val;
+    T val{};
     if (!tryRead(val)) {
       std::__throw_out_of_range("underflow");
     }
     if (!tryRead(val)) {
       std::__throw_out_of_range("underflow");
     }