Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

out-of-bounds access in splash_point #2

Open
jaideep777 opened this issue Jun 8, 2024 · 0 comments
Open

out-of-bounds access in splash_point #2

jaideep777 opened this issue Jun 8, 2024 · 0 comments

Comments

@jaideep777
Copy link

AI is not initialized, leading to potential segfault, and update of AI is happening at the wrong index. See comments "Jaideep FIXME" in below code:

	if(length(Au)==1){
		#if there is no information on how many cell drain to this point, assume 3 sides of the octogonal cell
		ncellin<-3
		ncellout<-3
		soil_info<-c(SAT,WP,FC,soil_info$Ksat,lambda,depth,bub_press,RES,Au[1],resolution^2,ncellin,ncellout,0)
		# ^ Jaideep FIXME: Note that this does not set soil_info[13] to AI. This means that when this is dereferenced in quick-run, there's a risk of segfault or garbage value
	}else{
		ncellin<-Au[2]
		ncellout<-Au[3]
		soil_info<-c(SAT,WP,FC,soil_info$Ksat,lambda,depth,bub_press,RES,Au[1],resolution^2,ncellin,ncellout,1)
	}

And here:

	initial_AI<-my_splash$spin_up(as.integer(365), as.integer(y[1]), as.numeric(sw_av[1:365]), as.numeric(tc_av[1:365]),as.numeric(pn_av[1:365]),slop,asp,as.numeric(snowf_av[1:365]),soil_info)
	# ^ Jaideep FIXME: This sees a size-12 soil_info when length(Au)=1, so might get segfault, or worse, AI will get garbage value 
	#update aridity
	soil_info[13]<-sum(initial_AI$pet,na.rm=T)/sum(Pinit[1:365],na.rm = T)
	# ^ Jaideep FIXME: This is assigning AI to soil_info[12] (R indexing) which is ncellout. It should instead go into soil_info[13] (R indexing), i.e. soil_info[12] (C++ indexing)
	# run spin up


``
jaideep777 added a commit to jaideep777/rsplash that referenced this issue Jun 8, 2024
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

No branches or pull requests

1 participant