Commit 777c3ca98fd2082d379e2d718a9ece4701c97350
1 parent
6ec889c4
Exists in
master
and in
72 other branches
Fix buffer init in ncinfo_remote
Showing
1 changed file
with
10 additions
and
5 deletions
Show diff stats
php/src/ncinfo_remote.c
... | ... | @@ -50,16 +50,17 @@ main(int argc, char **argv) |
50 | 50 | printf("Incorrect number of arguments\n"); |
51 | 51 | exit(1); |
52 | 52 | } |
53 | - | |
53 | + | |
54 | 54 | infoId = atoi(argv[3]); |
55 | 55 | |
56 | - stat = nc_open(argv[1],NC_WRITE|NC_SHARE,&ncID); check(stat); | |
56 | + stat = nc_open(argv[1],0,&ncID); check(stat); | |
57 | 57 | |
58 | 58 | stat = nc_inq_varid(ncID, argv[2], &varID); check(stat); |
59 | + | |
59 | 60 | stat = nc_inq_varndims(ncID, varID, &ndims); check(stat); |
60 | - | |
61 | + | |
61 | 62 | stat = nc_inq_vardimid(ncID, varID, dimids); check(stat); |
62 | - | |
63 | + | |
63 | 64 | size_t len = 0; |
64 | 65 | // size |
65 | 66 | if (ndims > 1) |
... | ... | @@ -85,7 +86,8 @@ main(int argc, char **argv) |
85 | 86 | fprintf(stdout, "-1"); |
86 | 87 | exit(0); |
87 | 88 | } |
88 | - unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); | |
89 | + unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); | |
90 | + memset(string_attr, 0, attlen * sizeof(char*)); | |
89 | 91 | stat = nc_get_att(ncID, varID, "LABL_PTR_1", string_attr); |
90 | 92 | if (stat != NC_NOERR) { |
91 | 93 | fprintf(stdout, "-1"); |
... | ... | @@ -116,6 +118,7 @@ main(int argc, char **argv) |
116 | 118 | unsigned char *string_var = (unsigned char *)malloc(length * sizeof(char*)); |
117 | 119 | for (i = 0; i < size; i++) |
118 | 120 | { |
121 | + memset(string_var, 0, length * sizeof(char*)); | |
119 | 122 | stat = nc_get_vara(ncID, labelID, start, count, string_var); check(stat); |
120 | 123 | fprintf(stdout, "%s", string_var); |
121 | 124 | if (i < size -1) fprintf(stdout,","); |
... | ... | @@ -131,6 +134,7 @@ main(int argc, char **argv) |
131 | 134 | stat = nc_inq_attlen(ncID, varID, info[infoId-2], &attlen); check(stat); |
132 | 135 | |
133 | 136 | unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); |
137 | + memset(string_attr, 0, attlen * sizeof(char*)); | |
134 | 138 | stat = nc_get_att(ncID, varID, info[infoId-2], string_attr); check(stat); |
135 | 139 | fprintf(stdout, "%s", string_attr); |
136 | 140 | free(string_attr); |
... | ... | @@ -169,6 +173,7 @@ main(int argc, char **argv) |
169 | 173 | } |
170 | 174 | else { |
171 | 175 | unsigned char *string_attr = (unsigned char *)malloc(attlen * sizeof(char*)); |
176 | + memset(string_attr, 0, attlen * sizeof(char*)); | |
172 | 177 | stat = nc_get_att(ncID, varID, info[infoId-1], string_attr); |
173 | 178 | if (strcasecmp(string_attr,"spectrogram") != 0) |
174 | 179 | fprintf(stdout, "0"); | ... | ... |