diff --git a/php/src/ncvar_attr.c b/php/src/ncvar_attr.c index e041a0e..2318f6e 100644 --- a/php/src/ncvar_attr.c +++ b/php/src/ncvar_attr.c @@ -52,9 +52,10 @@ main(int argc, char **argv) if (xtype == NC_CHAR) { size_t attlen = 0; check(nc_inq_attlen(ncID, varID, name_in, &attlen)); - unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*) + 1); check(nc_get_att(ncID, varID, name_in, string_attr)); + strcpy(&string_attr[attlen],"\0"); fprintf(stdout, "%s\n", string_attr); free(string_attr); } -- libgit2 0.21.2