Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Initialize pointers to fix compiler warnings about uninitialized local variables#1210

Merged
johnhaley81 merged 1 commit intonodegit:masternodegit/nodegit:masterfrom
rcjsuen:init-pointersrcjsuen/nodegit:init-pointersCopy head branch name to clipboard
Feb 26, 2017
Merged

Initialize pointers to fix compiler warnings about uninitialized local variables#1210
johnhaley81 merged 1 commit intonodegit:masternodegit/nodegit:masterfrom
rcjsuen:init-pointersrcjsuen/nodegit:init-pointersCopy head branch name to clipboard

Conversation

@rcjsuen
Copy link
Member

@rcjsuen rcjsuen commented Feb 1, 2017

When compiling the C++ bridge code, you will see several warnings about the use of uninitialized variables.

Linux / OSX

../src/config.cc:376:2: warning: variable 'from_tx' is uninitialized when used here [-Wuninitialized]
*from_tx = Nan::ObjectWrap::Unwrap<GitTransaction>(info[0]->ToObject())->GetValue();
 ^~~~~~~
../src/config.cc:375:29: note: initialize the variable 'from_tx' to silence this warning
  git_transaction ** from_tx;
                            ^
                             = nullptr

Windows

nodegit\src\tree.cc(588): warning C4700: uninitialized local variable 'from_dest' used [nodegit\build\nodegit.vcxproj]
nodegit\src\rebase.cc(486): warning C4700: uninitialized local variable 'from_index' used [nodegit\build\nodegit.vcxproj]
nodegit\src\libgit2.cc(164): warning C4700: uninitialized local variable 'from_major' used [nodegit\build\nodegit.vcxproj]
nodegit\src\libgit2.cc(168): warning C4700: uninitialized local variable 'from_minor' used [nodegit\build\nodegit.vcxproj]
nodegit\src\libgit2.cc(172): warning C4700: uninitialized local variable 'from_rev' used [nodegit\build\nodegit.vcxproj]
nodegit\src\config.cc(362): warning C4700: uninitialized local variable 'from_tx' used [nodegit\build\nodegit.vcxproj]
nodegit\src\index.cc(1511): warning C4700: uninitialized local variable 'from_at_pos' used [nodegit\build\nodegit.vcxproj]
nodegit\src\tree_entry.cc(219): warning C4700: uninitialized local variable 'from_object_out' used [nodegit\build\nodegit.vcxproj]
nodegit\src\commit.cc(2364): warning C4700: uninitialized local variable 'from_tree_out' used [nodegit\build\nodegit.vcxproj]
nodegit\src\tag.cc(1767): warning C4700: uninitialized local variable 'from_tag_target_out' used [nodegit\build\nodegit.vcxproj]
nodegit\src\status.cc(665): warning C4700: uninitialized local variable 'from_ignored' used [nodegit\build\nodegit.vcxproj]
nodegit\src\revparse.cc(67): warning C4700: uninitialized local variable 'from_object_out' used [nodegit\build\nodegit.vcxproj]
nodegit\src\revparse.cc(71): warning C4700: uninitialized local variable 'from_reference_out' used [nodegit\build\nodegit.vcxproj]

The warnings above can easily be fixed by initializing these pointer variables to NULL. We should strive to have as few warnings as possible in the code (if not zero) to make the compilation logs more readable by improving the signal to noise ratio wherever possible.

In convert_from_v8.cc, the unwrapping of values uses two separate lines
of code for variable declaration and variable assignment. When a
pointer (or double pointer) is present, the assignment to the newly
declared variable creates a compiler warning. To prevent the
compilation logs from filling up unnecessarily, pointer variables
should initially be assigned a `NULL` value upon its declaration so
that the compiler will not emit a warning on the subseqent variable
assignment line.
@johnhaley81
Copy link
Collaborator

The compiler warnings have been bugging me for awhile. Thanks for fixing some of them!

@johnhaley81 johnhaley81 merged commit d7e1e91 into nodegit:master Feb 26, 2017
@rcjsuen rcjsuen deleted the init-pointers branch February 26, 2017 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.