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)
|
static char *markup_quote(char *str)
|
||||||
{
|
{
|
||||||
assert(str);
|
if (!str)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
str = string_replace_all("&", "&", str);
|
str = string_replace_all("&", "&", str);
|
||||||
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)
|
static char *markup_unquote(char *str)
|
||||||
{
|
{
|
||||||
assert(str);
|
if (!str)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
str = string_replace_all(""", "\"", str);
|
str = string_replace_all(""", "\"", str);
|
||||||
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)
|
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);
|
||||||
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)
|
void markup_strip_a(char **str, char **urls)
|
||||||
{
|
{
|
||||||
|
assert(*str);
|
||||||
char *tag1 = NULL;
|
char *tag1 = NULL;
|
||||||
|
|
||||||
if (urls)
|
if (urls)
|
||||||
|
13
src/utils.c
13
src/utils.c
@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
char *string_replace_char(char needle, char replacement, char *haystack)
|
char *string_replace_char(char needle, char replacement, char *haystack)
|
||||||
{
|
{
|
||||||
|
if (!haystack)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
char *current = haystack;
|
char *current = haystack;
|
||||||
while ((current = strchr(current, needle)))
|
while ((current = strchr(current, needle)))
|
||||||
*current++ = replacement;
|
*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)
|
char *string_replace_at(char *buf, int pos, int len, const char *repl)
|
||||||
{
|
{
|
||||||
|
assert(buf);
|
||||||
|
assert(repl);
|
||||||
|
|
||||||
char *tmp;
|
char *tmp;
|
||||||
int size, buf_len, repl_len;
|
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)
|
char *string_replace_all(const char *needle, const char *replacement, char *haystack)
|
||||||
{
|
{
|
||||||
|
if (!haystack)
|
||||||
|
return NULL;
|
||||||
|
assert(needle);
|
||||||
|
assert(replacement);
|
||||||
|
|
||||||
char *start;
|
char *start;
|
||||||
int needle_pos;
|
int needle_pos;
|
||||||
int needle_len, repl_len;
|
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)
|
void string_strip_delimited(char *str, char a, char b)
|
||||||
{
|
{
|
||||||
|
assert(str);
|
||||||
|
|
||||||
int iread=-1, iwrite=0, copen=0;
|
int iread=-1, iwrite=0, copen=0;
|
||||||
while (str[++iread] != 0) {
|
while (str[++iread] != 0) {
|
||||||
if (str[iread] == a) {
|
if (str[iread] == a) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user