mirror of
				https://github.com/SuperBFG7/ympd
				synced 2025-10-30 21:33:00 +00:00 
			
		
		
		
	Fix: malloc errors
This commit is contained in:
		
							
								
								
									
										20
									
								
								src/list.c
									
									
									
									
									
								
							
							
						
						
									
										20
									
								
								src/list.c
									
									
									
									
									
								
							| @@ -31,17 +31,17 @@ int list_swap_item(struct node *n1, struct node *n2) { | |||||||
|         return 1; |         return 1; | ||||||
|          |          | ||||||
|     int value = n2->value; |     int value = n2->value; | ||||||
|     char *data; |     char *data = strdup(n2->data); | ||||||
|     data = malloc(strlen(n2->data)); |  | ||||||
|     data = strdup(n2->data); |  | ||||||
|      |      | ||||||
|     n2->value = n1->value; |     n2->value = n1->value; | ||||||
|     n2->data = realloc(n2->data, strlen(n1->data)); |     n2->data = realloc(n2->data, strlen(n1->data) + 1); | ||||||
|     n2->data = strdup(n1->data); |     if (n2->data) | ||||||
|  |         strcpy(n2->data, n1->data); | ||||||
|      |      | ||||||
|     n1->value = value; |     n1->value = value; | ||||||
|     n1->data = realloc(n1->data, strlen(data)); |     n1->data = realloc(n1->data, strlen(data) + 1); | ||||||
|     n1->data = strdup(data); |     if (n1->data) | ||||||
|  |         strcpy(n1->data, data); | ||||||
|      |      | ||||||
|     free(data); |     free(data); | ||||||
|     return 0; |     return 0; | ||||||
| @@ -78,15 +78,15 @@ int list_replace(struct list *l, int pos, char *data, int value) { | |||||||
|     } |     } | ||||||
|      |      | ||||||
|     current->value = value; |     current->value = value; | ||||||
|     current->data = realloc(current->data, strlen(data)); |     current->data = realloc(current->data, strlen(data) + 1); | ||||||
|     current->data = strdup(data); |     if (current->data) | ||||||
|  |         strcpy(current->data, data); | ||||||
|     return 0; |     return 0; | ||||||
| } | } | ||||||
|  |  | ||||||
| int list_push(struct list *l, char *data, int value) { | int list_push(struct list *l, char *data, int value) { | ||||||
|     struct node *n = malloc(sizeof(struct node)); |     struct node *n = malloc(sizeof(struct node)); | ||||||
|     n->value = value; |     n->value = value; | ||||||
|     n->data = malloc(strlen(data)); |  | ||||||
|     n->data = strdup(data); |     n->data = strdup(data); | ||||||
|     n->next = NULL; |     n->next = NULL; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -55,7 +55,7 @@ void callback_mympd(struct mg_connection *nc, const struct mg_str msg) { | |||||||
|     size_t n = 0; |     size_t n = 0; | ||||||
|     char *cmd; |     char *cmd; | ||||||
|     unsigned int uint_buf1, uint_buf2, uint_rc; |     unsigned int uint_buf1, uint_buf2, uint_rc; | ||||||
|     int je, int_buf1, int_buf2, int_rc;  |     int je, int_buf1, int_rc;  | ||||||
|     float float_buf; |     float float_buf; | ||||||
|     char *p_charbuf1, *p_charbuf2, *p_charbuf3, *p_charbuf4; |     char *p_charbuf1, *p_charbuf2, *p_charbuf3, *p_charbuf4; | ||||||
|     char p_char[4]; |     char p_char[4]; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 jcorporation
					jcorporation