Skip to content

Commit a4e0a53

Browse files
committed
Fix security issues and code smells
1 parent 873026b commit a4e0a53

File tree

3 files changed

+22
-7
lines changed

3 files changed

+22
-7
lines changed

applications/enigma_app.cxx

+8-6
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44

55
#include "boost/algorithm/string.hpp"
66

7-
void apply_rsg(const std::vector<int> ringstellung, Enigma* eg)
7+
void apply_rsg(const std::vector<int> ringstellung, Enigma& eg)
88
{
99
for(unsigned int i{0}; i < ringstellung.size(); ++i)
1010
{
11-
eg->ringstellung(eg->getRotorLabels()[i], ringstellung[i]);
11+
eg.ringstellung(eg.getRotorLabels()[i], ringstellung[i]);
1212
}
1313
}
1414

@@ -24,7 +24,7 @@ bool is_word(const std::string& s)
2424

2525
int main(int argc, char** argv)
2626
{
27-
Enigma* enigma = new Enigma;
27+
2828
std::string eg_version = EnigmaInfo::version;
2929

3030
if(EnigmaInfo::isBeta)
@@ -123,7 +123,9 @@ int main(int argc, char** argv)
123123
rotors.push_back(_temp);
124124
}
125125
}
126-
enigma = new Enigma(rotors, 'B', (key.size() == 3) ? "M3" : "M4", false);
126+
127+
auto enigma = std::make_unique<Enigma>(rotors, 'B', (key.size() == 3) ? "M3" : "M4", false);
128+
127129
enigma->set_key(key);
128130

129131
std::vector<int> rsg_settings = {0,0,0,0};
@@ -177,7 +179,7 @@ int main(int argc, char** argv)
177179
rsg_settings.push_back(_temp);
178180
}
179181

180-
apply_rsg(rsg_settings, enigma);
182+
apply_rsg(rsg_settings, *enigma);
181183
}
182184

183185
char input[100] = {0};
@@ -193,7 +195,7 @@ int main(int argc, char** argv)
193195
std::cout << "Resetting Machine..." << std::endl;
194196
enigma->reset();
195197
enigma->set_key(key);
196-
apply_rsg(rsg_settings, enigma);
198+
apply_rsg(rsg_settings, *enigma);
197199
}
198200
else
199201
{

include/Reflector.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Reflector
1313
public:
1414
Reflector(const char name, const std::map<char, char> ref_dict) :
1515
_reflector_dict(ref_dict), _name(name) {}
16-
char reflector_conversion(const char& letter) const {return _reflector_dict[letter];}
16+
char reflector_conversion(const char& letter) const {return _reflector_dict.at(letter);}
1717
};
1818

1919
class Reflector_B : public Reflector

sonar-project.properties

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sonar.projectKey=artemis-beta_enigma-cpp
2+
sonar.organization=artemis-beta
3+
4+
# This is the name and version displayed in the SonarCloud UI.
5+
#sonar.projectName=ROSPkgManager
6+
#sonar.projectVersion=1.0
7+
8+
# Path is relative to the sonar-project.properties file. Replace "\" by "/" on Windows.
9+
sonar.sources=src,include,logging/src,logging/include
10+
sonar.cpd.cpp.minimumtokens=400
11+
12+
# Encoding of the source code. Default is default system encoding
13+
#sonar.sourceEncoding=UTF-8

0 commit comments

Comments
 (0)