Skip to content

Commit a8d965f

Browse files
committed
Added +1 to string memory allocations.
1 parent fe53cfa commit a8d965f

4 files changed

Lines changed: 4 additions & 4 deletions

File tree

posts/unified-memory/dataElem.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ int main(void)
4646
e = (DataElement*)malloc(sizeof(DataElement));
4747

4848
e->value = 10;
49-
e->name = (char*)malloc(sizeof(char) * strlen("hello") );
49+
e->name = (char*)malloc(sizeof(char) * (strlen("hello") + 1));
5050
strcpy(e->name, "hello");
5151

5252
launch(e);

posts/unified-memory/dataElem_um.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ int main(void)
2626
cudaMallocManaged((void**)&e, sizeof(DataElement));
2727

2828
e->value = 10;
29-
cudaMallocManaged((void**)&(e->name), sizeof(char) * strlen("hello") );
29+
cudaMallocManaged((void**)&(e->name), sizeof(char) * (strlen("hello") + 1) );
3030
strcpy(e->name, "hello");
3131

3232
launch(e);

posts/unified-memory/dataElem_um_c++_1.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ int main(void)
3939
DataElement *e = new DataElement;
4040

4141
e->value = 10;
42-
cudaMallocManaged((void**)&(e->name), sizeof(char) * strlen("hello") );
42+
cudaMallocManaged((void**)&(e->name), sizeof(char) * (strlen("hello") + 1) );
4343
strcpy(e->name, "hello");
4444

4545
launch(e);

posts/unified-memory/dataElem_um_c++_2.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private:
5858
void _realloc(int len) {
5959
cudaFree(data);
6060
length = len;
61-
cudaMallocManaged(&data, length);
61+
cudaMallocManaged(&data, length+1);
6262
}
6363
};
6464

0 commit comments

Comments
 (0)