Skip to content

Commit f365464

Browse files
author
Moritz
committed
Removed const_cast<char*>("literal").
Replaced it with strdup("literal") throughout the code.
1 parent 6c1308b commit f365464

File tree

4 files changed

+20
-20
lines changed

4 files changed

+20
-20
lines changed

src/ovf.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ catch( ... )
4848
void ovf_segment_initialize(struct ovf_segment * ovf_segment_ptr)
4949
try
5050
{
51-
ovf_segment_ptr->title = const_cast<char *>("");
52-
ovf_segment_ptr->comment = const_cast<char *>("");
51+
ovf_segment_ptr->title = strdup("");
52+
ovf_segment_ptr->comment = strdup("");
5353
ovf_segment_ptr->valuedim = 0;
54-
ovf_segment_ptr->valueunits = const_cast<char *>("");
55-
ovf_segment_ptr->valuelabels = const_cast<char *>("");
56-
ovf_segment_ptr->meshtype = const_cast<char *>("");
57-
ovf_segment_ptr->meshunit = const_cast<char *>("");
54+
ovf_segment_ptr->valueunits = strdup("");
55+
ovf_segment_ptr->valuelabels = strdup("");
56+
ovf_segment_ptr->meshtype = strdup("");
57+
ovf_segment_ptr->meshunit = strdup("");
5858
ovf_segment_ptr->pointcount = 0;
5959
ovf_segment_ptr->n_cells[0] = 0;
6060
ovf_segment_ptr->n_cells[1] = 0;

test/atomistic.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include <ovf.h>
44
#include <fmt/format.h>
55

6-
76
#include <iostream>
87
#include <cstring>
98

@@ -15,8 +14,8 @@ void ovf_test_write(std::string filename, std::string meshtype, int ovf_extensio
1514
{
1615
// segment header
1716
auto segment = ovf_segment_create();
18-
segment->title = const_cast<char *>("ovf test title - write");
19-
segment->comment = const_cast<char *>("test write");
17+
segment->title = strdup("ovf test title - write");
18+
segment->comment = strdup("test write");
2019
segment->valuedim = 3;
2120

2221
segment->n_cells[0] = 2;
@@ -65,8 +64,8 @@ void ovf_test_write(std::string filename, std::string meshtype, int ovf_extensio
6564
{
6665
// Append second
6766
auto segment = ovf_segment_create();
68-
segment->title = const_cast<char *>("ovf test title - append");
69-
segment->comment = const_cast<char *>("test append");
67+
segment->title = strdup("ovf test title - append");
68+
segment->comment = strdup("test append");
7069
segment->valuedim = 3;
7170
segment->n_cells[0] = 2;
7271
segment->n_cells[1] = 2;

test/binary.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ TEST_CASE( "Mixed binary and CSV", "[mixed]" )
152152
{
153153
// segment header
154154
auto segment = ovf_segment_create();
155-
segment->title = const_cast<char *>("ovf test title - write");
156-
segment->comment = const_cast<char *>("test write csv");
155+
segment->title = strdup("ovf test title - write");
156+
segment->comment = strdup("test write csv");
157157
segment->valuedim = 3;
158158
segment->n_cells[0] = 2;
159159
segment->n_cells[1] = 2;

test/simple.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <catch.hpp>
22

33
#include <ovf.h>
4+
#include <cstring>
45

56
#include <iostream>
67

@@ -24,8 +25,8 @@ TEST_CASE( "Write", "[write]" )
2425
{
2526
// segment header
2627
auto segment = ovf_segment_create();
27-
segment->title = const_cast<char *>("ovf test title - write");
28-
segment->comment = const_cast<char *>("test write");
28+
segment->title = strdup("ovf test title - write");
29+
segment->comment = strdup("test write");
2930
segment->valuedim = 3;
3031
segment->n_cells[0] = 2;
3132
segment->n_cells[1] = 2;
@@ -56,8 +57,8 @@ TEST_CASE( "Write", "[write]" )
5657
{
5758
// segment header
5859
auto segment = ovf_segment_create();
59-
segment->title = const_cast<char *>("ovf test title - append");
60-
segment->comment = const_cast<char *>("test append");
60+
segment->title = strdup("ovf test title - append");
61+
segment->comment = strdup("test append");
6162
segment->valuedim = 3;
6263
segment->n_cells[0] = 2;
6364
segment->n_cells[1] = 2;
@@ -88,10 +89,10 @@ TEST_CASE( "Write", "[write]" )
8889
{
8990
// segment header
9091
auto segment = ovf_segment_create();
91-
segment->title = const_cast<char *>("ovf test title - append irregular mesh");
92-
segment->comment = const_cast<char *>("an irregular mesh has different keywords than a rectangular one");
92+
segment->title = strdup("ovf test title - append irregular mesh");
93+
segment->comment = strdup("an irregular mesh has different keywords than a rectangular one");
9394
segment->valuedim = 3;
94-
segment->meshtype = const_cast<char *>("irregular");
95+
segment->meshtype = strdup("irregular");
9596
segment->pointcount = 4;
9697

9798
// data

0 commit comments

Comments
 (0)