Skip to content

Commit

Permalink
Corrected malloc statements (#514)
Browse files Browse the repository at this point in the history
Changed sizeof(char *) to sizeof(char) to malloc an array of chars.
  • Loading branch information
bmribler authored Feb 13, 2024
1 parent be9b9c9 commit 84ed150
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
8 changes: 4 additions & 4 deletions hdf/test/tvnameclass.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -115,7 +115,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand All @@ -138,7 +138,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -155,7 +155,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand Down
22 changes: 11 additions & 11 deletions hdf/test/tvset.c
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ read_vset_stuff(void)
status = Vgetnamelen(vg1, &name_len);
CHECK(status, FAIL, "Vgetnamelen:vg1");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "read_vset_stuff");

status = Vgetname(vg1, vgname);
Expand All @@ -604,7 +604,7 @@ read_vset_stuff(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK(status, FAIL, "Vgetclassnamelen:vg1");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "read_vset_stuff");

status = Vgetclass(vg1, vgclass);
Expand Down Expand Up @@ -1823,7 +1823,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -1840,7 +1840,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand All @@ -1867,7 +1867,7 @@ test_vglongnames(void)
status = Vgetnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgname = (char *)malloc(sizeof(char *) * (name_len + 1));
vgname = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgname, "vgname", "test_vglongnames");

status = Vgetname(vg1, vgname);
Expand All @@ -1884,7 +1884,7 @@ test_vglongnames(void)
status = Vgetclassnamelen(vg1, &name_len);
CHECK_VOID(status, FAIL, "Vgetnamelen");

vgclass = (char *)malloc(sizeof(char *) * (name_len + 1));
vgclass = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(vgclass, "vgclass", "test_vglongnames");

status = Vgetclass(vg1, vgclass);
Expand Down Expand Up @@ -2749,7 +2749,7 @@ test_extfile(void)
name_len = VSgetexternalfile(vdata1_id, 0, NULL, NULL);
VERIFY_VOID(name_len, (intn)strlen(EXTERNAL_FILE), "VSgetexternalfile");

extfile_name = (char *)malloc(sizeof(char *) * (name_len + 1));
extfile_name = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(extfile_name, "extfile_name", "test_extfile");

/* Old function: Get the external file name - VSgetexternalfile
Expand All @@ -2764,7 +2764,7 @@ test_extfile(void)
name_len = VSgetexternalinfo(vdata1_id, 0, NULL, NULL, NULL);
VERIFY_VOID(name_len, (intn)strlen(EXTERNAL_FILE), "VSgetexternalinfo");

extfile_name = (char *)malloc(sizeof(char *) * (name_len + 1));
extfile_name = (char *)malloc(sizeof(char) * (name_len + 1));
CHECK_ALLOC(extfile_name, "extfile_name", "test_extfile");

/* Get the external file name */
Expand All @@ -2777,13 +2777,13 @@ test_extfile(void)
name should be truncated */
{
/* Make a shorter string to verify later */
char *short_name = (char *)malloc(sizeof(char *) * (name_len));
char *short_name = (char *)malloc(sizeof(char) * (name_len));
memset(short_name, '\0', name_len);
strncpy(short_name, EXTERNAL_FILE, name_len - 2);

/* Prepare buffer for external file name in the following test */
extfile_name = (char *)malloc(sizeof(char *) * (name_len - 1));
memset(extfile_name, '\0', name_len);
extfile_name = (char *)malloc(sizeof(char) * (name_len - 1));
memset(extfile_name, '\0', name_len - 1);

/* Call VSgetexternalinfo again with smaller buffer size and make sure
VSgetexternalinfo reads the name truncated to the given buffer size*/
Expand Down

0 comments on commit 84ed150

Please sign in to comment.