Use assertions and NULL checks in markup and utils
This commit is contained in:
		
							parent
							
								
									90b04a22dd
								
							
						
					
					
						commit
						413c0d68af
					
				
							
								
								
									
										10
									
								
								src/markup.c
									
									
									
									
									
								
							
							
						
						
									
										10
									
								
								src/markup.c
									
									
									
									
									
								
							| @ -14,7 +14,8 @@ | ||||
| 
 | ||||
| static char *markup_quote(char *str) | ||||
| { | ||||
|         assert(str); | ||||
|         if (!str) | ||||
|                 return NULL; | ||||
| 
 | ||||
|         str = string_replace_all("&", "&", str); | ||||
|         str = string_replace_all("\"", """, str); | ||||
| @ -27,7 +28,8 @@ static char *markup_quote(char *str) | ||||
| 
 | ||||
| static char *markup_unquote(char *str) | ||||
| { | ||||
|         assert(str); | ||||
|         if (!str) | ||||
|                 return NULL; | ||||
| 
 | ||||
|         str = string_replace_all(""", "\"", str); | ||||
|         str = string_replace_all("'", "'", str); | ||||
| @ -40,7 +42,8 @@ static char *markup_unquote(char *str) | ||||
| 
 | ||||
| static char *markup_br2nl(char *str) | ||||
| { | ||||
|         assert(str); | ||||
|         if (!str) | ||||
|                 return NULL; | ||||
| 
 | ||||
|         str = string_replace_all("<br>", "\n", str); | ||||
|         str = string_replace_all("<br/>", "\n", str); | ||||
| @ -57,6 +60,7 @@ static char *markup_br2nl(char *str) | ||||
|  */ | ||||
| void markup_strip_a(char **str, char **urls) | ||||
| { | ||||
|         assert(*str); | ||||
|         char *tag1 = NULL; | ||||
| 
 | ||||
|         if (urls) | ||||
|  | ||||
							
								
								
									
										13
									
								
								src/utils.c
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								src/utils.c
									
									
									
									
									
								
							| @ -13,6 +13,9 @@ | ||||
| 
 | ||||
| char *string_replace_char(char needle, char replacement, char *haystack) | ||||
| { | ||||
|         if (!haystack) | ||||
|                 return NULL; | ||||
| 
 | ||||
|         char *current = haystack; | ||||
|         while ((current = strchr(current, needle))) | ||||
|                 *current++ = replacement; | ||||
| @ -21,6 +24,9 @@ char *string_replace_char(char needle, char replacement, char *haystack) | ||||
| 
 | ||||
| char *string_replace_at(char *buf, int pos, int len, const char *repl) | ||||
| { | ||||
|         assert(buf); | ||||
|         assert(repl); | ||||
| 
 | ||||
|         char *tmp; | ||||
|         int size, buf_len, repl_len; | ||||
| 
 | ||||
| @ -47,6 +53,11 @@ char *string_replace_at(char *buf, int pos, int len, const char *repl) | ||||
| 
 | ||||
| char *string_replace_all(const char *needle, const char *replacement, char *haystack) | ||||
| { | ||||
|         if (!haystack) | ||||
|                 return NULL; | ||||
|         assert(needle); | ||||
|         assert(replacement); | ||||
| 
 | ||||
|         char *start; | ||||
|         int needle_pos; | ||||
|         int needle_len, repl_len; | ||||
| @ -106,6 +117,8 @@ char *string_strip_quotes(const char *value) | ||||
| 
 | ||||
| void string_strip_delimited(char *str, char a, char b) | ||||
| { | ||||
|         assert(str); | ||||
| 
 | ||||
|         int iread=-1, iwrite=0, copen=0; | ||||
|         while (str[++iread] != 0) { | ||||
|                 if (str[iread] == a) { | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Benedikt Heine
						Benedikt Heine