[PATCH] Cleanup some uninitialized variables

Dirk Hohndel dirk at hohndel.org
Wed Dec 4 15:55:40 UTC 2013


I agree... but playing with this I noticed something else that was odd
(and that wasn't introduced by your change)...

When selecting table print, it's only printing the first 251 of my 267
dives... and leaves empty space at the bottom of the last page.

Haven't really dug into this, just pointing it out (I guess I should
heed my own advise and file a bug)

/D

On Thu, 2013-12-05 at 00:48 +0100, Anton Lundin wrote:
> I can't really see any point in passing a local loop variable around,
> and copying a uninitialized pointer. Better use local variables there
> and let the compiler optimize them away if it feels for doing that.
> ---
>  qt-ui/printlayout.cpp | 16 ++++++++--------
>  qt-ui/printlayout.h   |  2 +-
>  2 files changed, 9 insertions(+), 9 deletions(-)
> 
> diff --git a/qt-ui/printlayout.cpp b/qt-ui/printlayout.cpp
> index 485d8a1..556bf13 100644
> --- a/qt-ui/printlayout.cpp
> +++ b/qt-ui/printlayout.cpp
> @@ -93,14 +93,16 @@ void PrintLayout::setup()
>  }
>  
>  // go trought the dive table and find how many dives we are a going to print
> -void PrintLayout::estimateTotalDives(struct dive *dive, int *i, int *total) const
> +int PrintLayout::estimateTotalDives() const
>  {
> -	*total = 0;
> -	for_each_dive(*i, dive) {
> +	int total = 0, i = 0;
> +	struct dive *dive;
> +	for_each_dive(i, dive) {
>  		if (!dive->selected && printOptions->print_selected)
>  			continue;
> -		(*total)++;
> +		total++;
>  	}
> +	return total;
>  }
>  
>  /* the used formula here is:
> @@ -116,9 +118,8 @@ void PrintLayout::estimateTotalDives(struct dive *dive, int *i, int *total) cons
>  
>  void PrintLayout::printProfileDives(int divesPerRow, int divesPerColumn)
>  {
> -	int i, row = 0, col = 0, printed = 0, total = 0;
> +	int i, row = 0, col = 0, printed = 0, total = estimateTotalDives();
>  	struct dive *dive;
> -	estimateTotalDives(dive, &i, &total);
>  	if (!total)
>  		return;
>  
> @@ -273,8 +274,7 @@ void PrintLayout::printTable()
>  {
>  	struct dive *dive;
>  	const int stage = 33; // there are 3 stages in this routine: 100% / 3 ~= 33%
> -	int i, row = 0, total, progress;
> -	estimateTotalDives(dive, &i, &total);
> +	int i, row = 0, progress, total = estimateTotalDives();
>  	if (!total)
>  		return;
>  
> diff --git a/qt-ui/printlayout.h b/qt-ui/printlayout.h
> index f21940a..077d7ac 100644
> --- a/qt-ui/printlayout.h
> +++ b/qt-ui/printlayout.h
> @@ -34,7 +34,7 @@ private:
>  	QList<unsigned int> profilePrintColumnWidths, profilePrintRowHeights;
>  
>  	void setup();
> -	void estimateTotalDives(struct dive *dive, int *i, int *total) const;
> +	int estimateTotalDives() const;
>  	void printProfileDives(int divesPerRow, int divesPerColumn);
>  	QTableView *createProfileTable(ProfilePrintModel *model, const int tableW);
>  	void printTable();




More information about the subsurface mailing list