mirror of
				https://github.com/YosysHQ/yosys
				synced 2025-10-31 11:42:30 +00:00 
			
		
		
		
	cxxrtl: fix escape_c_string hex literal fiasco.
				
					
				
			In C and C++, a `\x` escape sequence consumes as many hexadecimal digits as there are available, so it is not composable with arbitrary alnum characters afterwards. An octal escape sequence like `\000` always has fixed width, avoiding an issue where `\x01c` and `\x1c` produce the same string.
This commit is contained in:
		
							parent
							
								
									7294d8b5af
								
							
						
					
					
						commit
						43ddd89ba5
					
				
					 1 changed files with 5 additions and 4 deletions
				
			
		|  | @ -615,10 +615,11 @@ std::string escape_cxx_string(const std::string &input) | |||
| 				output.push_back('\\'); | ||||
| 			output.push_back(c); | ||||
| 		} else { | ||||
| 			char l = c & 0xf, h = (c >> 4) & 0xf; | ||||
| 			output.append("\\x"); | ||||
| 			output.push_back((h < 10 ? '0' + h : 'a' + h - 10)); | ||||
| 			output.push_back((l < 10 ? '0' + l : 'a' + l - 10)); | ||||
| 			char l = c & 0x3, m = (c >> 3) & 0x3, h = (c >> 6) & 0x3; | ||||
| 			output.append("\\"); | ||||
| 			output.push_back('0' + h); | ||||
| 			output.push_back('0' + m); | ||||
| 			output.push_back('0' + l); | ||||
| 		} | ||||
| 	} | ||||
| 	output.push_back('"'); | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue