Skip to content

Conversation

@mruddy
Copy link
Contributor

@mruddy mruddy commented Jun 30, 2018

Was getting the following compiler warning:

init.cpp: In function ‘bool AppInitMain()’:
init.cpp:1616:60: warning: ‘nStart’ may be used uninitialized in this function [-Wmaybe-uninitialized]
         LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);

It's ok without this PR, but this PR renames nStart to load_block_index_start_time, makes it const, and also reduces the scope of the variable.

The logging line is moved such that the the time spent will be logged even if a shutdown is requested while the index is being loaded.

Having the log message output even when a shutdown is requested may be how this was intended to work before anyways. That could explain the leading space, as such a log message now looks like:

2018-06-30T11:34:05Z [0%]...[16%]...[33%]...[50%]... block index           25750ms
2018-06-30T11:34:17Z Shutdown requested. Exiting.

@Empact
Copy link
Contributor

Empact commented Jul 1, 2018

utACK 2dcd7b4 - I couldn't follow the logic very easily so I did some refactoring in a branch to be sure I understood the cases in #13582

@maflcko
Copy link
Member

maflcko commented Jul 2, 2018

utACK 2dcd7b4

1 similar comment
@laanwj
Copy link
Member

laanwj commented Jul 5, 2018

utACK 2dcd7b4

@laanwj laanwj merged commit 2dcd7b4 into bitcoin:master Jul 5, 2018
laanwj added a commit that referenced this pull request Jul 5, 2018
…nitMain warning

2dcd7b4 logging: avoid nStart may be used uninitialized in AppInitMain warning (mruddy)

Pull request description:

  Was getting the following compiler warning:

  ```
  init.cpp: In function ‘bool AppInitMain()’:
  init.cpp:1616:60: warning: ‘nStart’ may be used uninitialized in this function [-Wmaybe-uninitialized]
           LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
  ```

  It's ok without this PR, but this PR renames `nStart` to `load_block_index_start_time`, makes it `const`, and also reduces the scope of the variable.

  The logging line is moved such that the the time spent will be logged even if a shutdown is requested while the index is being loaded.

  Having the log message output even when a shutdown is requested may be how this was intended to work before anyways. That could explain the leading space, as such a log message now looks like:
  ```
  2018-06-30T11:34:05Z [0%]...[16%]...[33%]...[50%]... block index           25750ms
  2018-06-30T11:34:17Z Shutdown requested. Exiting.
  ```

Tree-SHA512: 967048afbc31f2ce8f80ae7d33fee0bdcbe94550cf2b5b662087e2a7cff14a8bf43d909b30f930660c184ec6c3c7e1302a84e3e54fc1723f7412827f4bf2c518
@mruddy mruddy deleted the dev1 branch July 5, 2018 16:49
deadalnix pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Jun 18, 2020
…nitMain warning

Summary:
2dcd7b4 logging: avoid nStart may be used uninitialized in AppInitMain warning (mruddy)

Pull request description:

  Was getting the following compiler warning:

  ```
  init.cpp: In function ‘bool AppInitMain()’:
  init.cpp:1616:60: warning: ‘nStart’ may be used uninitialized in this function [-Wmaybe-uninitialized]
           LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
  ```

  It's ok without this PR, but this PR renames `nStart` to `load_block_index_start_time`, makes it `const`, and also reduces the scope of the variable.

  The logging line is moved such that the the time spent will be logged even if a shutdown is requested while the index is being loaded.

  Having the log message output even when a shutdown is requested may be how this was intended to work before anyways. That could explain the leading space, as such a log message now looks like:
  ```
  2018-06-30T11:34:05Z [0%]...[16%]...[33%]...[50%]... block index           25750ms
  2018-06-30T11:34:17Z Shutdown requested. Exiting.
  ```

Tree-SHA512: 967048afbc31f2ce8f80ae7d33fee0bdcbe94550cf2b5b662087e2a7cff14a8bf43d909b30f930660c184ec6c3c7e1302a84e3e54fc1723f7412827f4bf2c518

Backport of Core [[bitcoin/bitcoin#13577 | PR13577]]

Test Plan:
  ninja
  ninja check-all

Reviewers: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox

Reviewed By: O1 Bitcoin ABC, #bitcoin_abc, jasonbcox

Differential Revision: https://reviews.bitcoinabc.org/D6646
PastaPastaPasta pushed a commit to PastaPastaPasta/dash that referenced this pull request Jul 9, 2020
…in AppInitMain warning

2dcd7b4 logging: avoid nStart may be used uninitialized in AppInitMain warning (mruddy)

Pull request description:

  Was getting the following compiler warning:

  ```
  init.cpp: In function ‘bool AppInitMain()’:
  init.cpp:1616:60: warning: ‘nStart’ may be used uninitialized in this function [-Wmaybe-uninitialized]
           LogPrintf(" block index %15dms\n", GetTimeMillis() - nStart);
  ```

  It's ok without this PR, but this PR renames `nStart` to `load_block_index_start_time`, makes it `const`, and also reduces the scope of the variable.

  The logging line is moved such that the the time spent will be logged even if a shutdown is requested while the index is being loaded.

  Having the log message output even when a shutdown is requested may be how this was intended to work before anyways. That could explain the leading space, as such a log message now looks like:
  ```
  2018-06-30T11:34:05Z [0%]...[16%]...[33%]...[50%]... block index           25750ms
  2018-06-30T11:34:17Z Shutdown requested. Exiting.
  ```

Tree-SHA512: 967048afbc31f2ce8f80ae7d33fee0bdcbe94550cf2b5b662087e2a7cff14a8bf43d909b30f930660c184ec6c3c7e1302a84e3e54fc1723f7412827f4bf2c518
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants