Commit d1d33d9d3eb55edbb8d3dd2e46f1b57ecb0e4f5c
1 parent
ff419a92
Fixing memory errors
Showing
1 changed file
with
3 additions
and
1 deletions
mcplayerstat.c
@@ -13,12 +13,14 @@ void printInventory(TagList *inv) { | @@ -13,12 +13,14 @@ void printInventory(TagList *inv) { | ||
13 | if(!strncmp(attr.name,"Slot",attr.nameLength)) { | 13 | if(!strncmp(attr.name,"Slot",attr.nameLength)) { |
14 | slot = *((uint8_t*)attr.payload); | 14 | slot = *((uint8_t*)attr.payload); |
15 | } else if(!strncmp(attr.name,"id",attr.nameLength)) { | 15 | } else if(!strncmp(attr.name,"id",attr.nameLength)) { |
16 | - id = (char*)attr.payload; | 16 | + id = calloc(attr.payloadLength+1,sizeof(char)); |
17 | + memcpy(id,(char*)attr.payload,attr.payloadLength); | ||
17 | } else if(!strncmp(attr.name,"Count",attr.nameLength)) { | 18 | } else if(!strncmp(attr.name,"Count",attr.nameLength)) { |
18 | count = *((uint8_t*)attr.payload); | 19 | count = *((uint8_t*)attr.payload); |
19 | } | 20 | } |
20 | } | 21 | } |
21 | printf("\t- [%u] %ux %s\n",slot,count,id); | 22 | printf("\t- [%u] %ux %s\n",slot,count,id); |
23 | + free(id); | ||
22 | } | 24 | } |
23 | } | 25 | } |
24 | 26 |