mirror of
				https://github.com/cuberite/polarssl.git
				synced 2025-11-04 04:32:24 -05:00 
			
		
		
		
	Fix comment parsing
Fix cases like ``` /*short comment*/ /*long comment */ int mbedtls_foo; ``` where the previous code thought that the second line started outside of a comment and ended inside of a comment. I believe that the new code strips comments correctly. It also strips string literals, just in case. Fixes #5191. Signed-off-by: Gilles Peskine <Gilles.Peskine@arm.com>
This commit is contained in:
		
							parent
							
								
									09c02ee95f
								
							
						
					
					
						commit
						c8794202e6
					
				@ -509,18 +509,19 @@ class CodeParser():
 | 
				
			|||||||
                previous_line = ""
 | 
					                previous_line = ""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                for line_no, line in enumerate(header):
 | 
					                for line_no, line in enumerate(header):
 | 
				
			||||||
                    # Skip parsing this line if a block comment ends on it,
 | 
					                    # Terminate current comment?
 | 
				
			||||||
                    # but don't skip if it has just started -- there is a chance
 | 
					 | 
				
			||||||
                    # it ends on the same line.
 | 
					 | 
				
			||||||
                    if re.search(r"/\*", line):
 | 
					 | 
				
			||||||
                        in_block_comment = not in_block_comment
 | 
					 | 
				
			||||||
                    if re.search(r"\*/", line):
 | 
					 | 
				
			||||||
                        in_block_comment = not in_block_comment
 | 
					 | 
				
			||||||
                        continue
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    if in_block_comment:
 | 
					                    if in_block_comment:
 | 
				
			||||||
                        previous_line = ""
 | 
					                        line = re.sub(r".*?\*/", r"", line, 1)
 | 
				
			||||||
                        continue
 | 
					                        in_block_comment = False
 | 
				
			||||||
 | 
					                    # Remove full comments and string literals
 | 
				
			||||||
 | 
					                    line = re.sub(r'/\*.*?\*/|(")(?:[^\\\"]|\\.)*"',
 | 
				
			||||||
 | 
					                                  lambda s: '""' if s.group(1) else ' ',
 | 
				
			||||||
 | 
					                                  line)
 | 
				
			||||||
 | 
					                    # Start an unfinished comment?
 | 
				
			||||||
 | 
					                    m = re.match(r"/\*", line)
 | 
				
			||||||
 | 
					                    if m:
 | 
				
			||||||
 | 
					                        in_block_comment = True
 | 
				
			||||||
 | 
					                        line = line[:m.end(0)]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if exclusion_lines.search(line):
 | 
					                    if exclusion_lines.search(line):
 | 
				
			||||||
                        previous_line = ""
 | 
					                        previous_line = ""
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user