mirror of
				https://github.com/subsurface/subsurface.git
				synced 2025-02-19 22:16:15 +00:00 
			
		
		
		
	divelist.c: Fix possible NULL pointer deref.
calculate_cns(): The check if prev_dive is NULL should be before calling prev_dive->when. Reported by the program cppcheck. Signed-off-by: Lubomir I. Ivanov <neolit123@gmail.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
		
							parent
							
								
									ea895fbecc
								
							
						
					
					
						commit
						f09afad5a0
					
				
					 1 changed files with 6 additions and 4 deletions
				
			
		|  | @ -266,12 +266,14 @@ static int calculate_cns(struct dive *dive) | ||||||
| 	divenr = get_divenr(dive); | 	divenr = get_divenr(dive); | ||||||
| 	if (divenr) { | 	if (divenr) { | ||||||
| 		prev_dive = get_dive(divenr -1 ); | 		prev_dive = get_dive(divenr -1 ); | ||||||
|  | 		if (prev_dive) { | ||||||
| 			endtime = prev_dive->when + prev_dive->duration.seconds; | 			endtime = prev_dive->when + prev_dive->duration.seconds; | ||||||
| 		if (prev_dive && dive->when < (endtime + 3600 * 12)) { | 			if (dive->when < (endtime + 3600 * 12)) { | ||||||
| 				cns = calculate_cns(prev_dive); | 				cns = calculate_cns(prev_dive); | ||||||
| 				cns = cns * 1/pow(2, (dive->when - endtime) / (90.0 * 60.0)); | 				cns = cns * 1/pow(2, (dive->when - endtime) / (90.0 * 60.0)); | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  | 	} | ||||||
| 	/* Caclulate the cns for each sample in this dive and sum them */ | 	/* Caclulate the cns for each sample in this dive and sum them */ | ||||||
| 	for (i = 1; i < dc->samples; i++) { | 	for (i = 1; i < dc->samples; i++) { | ||||||
| 		int t; | 		int t; | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue