json-to-value: Throw sensible error message on invalid numbers
This commit is contained in:
		
							parent
							
								
									5d5b931fb1
								
							
						
					
					
						commit
						f9bcbddef2
					
				
					 1 changed files with 10 additions and 4 deletions
				
			
		|  | @ -106,10 +106,16 @@ static void parseJSON(EvalState & state, const char * & s, Value & v) | ||||||
|             tmp_number += *s++; |             tmp_number += *s++; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|         if (number_type == tFloat) |         try { | ||||||
|             mkFloat(v, stod(tmp_number)); |             if (number_type == tFloat) | ||||||
|         else |                 mkFloat(v, stod(tmp_number)); | ||||||
|             mkInt(v, stoi(tmp_number)); |             else | ||||||
|  |                 mkInt(v, stoi(tmp_number)); | ||||||
|  |         } catch (std::invalid_argument e) { | ||||||
|  |             throw JSONParseError("invalid JSON number"); | ||||||
|  |         } catch (std::out_of_range e) { | ||||||
|  |             throw JSONParseError("out-of-range JSON number"); | ||||||
|  |         } | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     else if (strncmp(s, "true", 4) == 0) { |     else if (strncmp(s, "true", 4) == 0) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue