Skip to content

Commit

Permalink
Try to fix bugs in insert operations
Browse files Browse the repository at this point in the history
when input string not null but *s==0, function will behave wrong
handle instances at above description
  • Loading branch information
Dayy0v0 committed Jan 6, 2024
1 parent 424f2d4 commit c35920d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions queue.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void q_free(struct list_head *l)
/* Insert an element at head of queue */
bool q_insert_head(struct list_head *head, char *s)
{
if (!head || !s)
if (!head || !s || (*s == '\0'))
return false;
element_t *elem = (element_t *) malloc(sizeof(element_t));
if (!elem)
Expand All @@ -58,7 +58,7 @@ bool q_insert_head(struct list_head *head, char *s)
/* Insert an element at tail of queue */
bool q_insert_tail(struct list_head *head, char *s)
{
if (!head || !s)
if (!head || !s || (*s == '\0'))
return false;
element_t *elem = (element_t *) malloc(sizeof(element_t));
if (!elem)
Expand Down

0 comments on commit c35920d

Please sign in to comment.