Skip to content

Commit

Permalink
Correct ato* clang warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
Ben RUBSON authored Nov 2, 2017
1 parent 135fe9e commit 4e19edf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
12 changes: 6 additions & 6 deletions encfs/FileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,7 @@ static Cipher::CipherAlgorithm selectCipherAlgorithm() {
cout << "\n" << _("Enter the number corresponding to your choice: ");
char answer[10];
char *res = fgets(answer, sizeof(answer), stdin);
int cipherNum = (res == nullptr ? 0 : atoi(answer));
int cipherNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10));
cout << "\n";

if (cipherNum < 1 || cipherNum > (int)algorithms.size()) {
Expand Down Expand Up @@ -688,7 +688,7 @@ static Interface selectNameCoding() {
cout << "\n" << _("Enter the number corresponding to your choice: ");
char answer[10];
char *res = fgets(answer, sizeof(answer), stdin);
int algNum = (res == nullptr ? 0 : atoi(answer));
int algNum = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10));
cout << "\n";

if (algNum < 1 || algNum > (int)algorithms.size()) {
Expand Down Expand Up @@ -755,7 +755,7 @@ static int selectKeySize(const Cipher::CipherAlgorithm &alg) {

char answer[10];
char *res = fgets(answer, sizeof(answer), stdin);
int keySize = (res == nullptr ? 0 : atoi(answer));
int keySize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10));
cout << "\n";

keySize = alg.keyLength.closest(keySize);
Expand Down Expand Up @@ -795,8 +795,8 @@ static int selectBlockSize(const Cipher::CipherAlgorithm &alg) {
char *res = fgets(answer, sizeof(answer), stdin);
cout << "\n";

if (res != nullptr && atoi(answer) >= alg.blockSize.min()) {
blockSize = atoi(answer);
if (res != nullptr && (int)strtol(answer, nullptr, 10) >= alg.blockSize.min()) {
blockSize = (int)strtol(answer, nullptr, 10);
}

blockSize = alg.blockSize.closest(blockSize);
Expand Down Expand Up @@ -900,7 +900,7 @@ static void selectBlockMAC(int *macBytes, int *macRandBytes, bool forceMac) {
char *res = fgets(answer, sizeof(answer), stdin);
cout << "\n";

randSize = (res == nullptr ? 0 : atoi(answer));
randSize = (res == nullptr ? 0 : (int)strtol(answer, nullptr, 10));
if (randSize < 0) {
randSize = 0;
}
Expand Down
26 changes: 19 additions & 7 deletions encfs/XmlReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include <algorithm> // for remove_if
#include <cstring> // for NULL
#include <fstream> // for ifstream
#include <limits>
#include <memory> // for shared_ptr
#include <sstream> // for ostringstream

Expand Down Expand Up @@ -60,7 +61,15 @@ bool XmlValue::read(const char *path, int *out) const {
return false;
}

*out = atoi(value->text().c_str());
char * e;
long lout = strtol(value->text().c_str(), &e, 10);
if (*e != '\0') {
return false;
}
if (lout < std::numeric_limits<int>::min() || lout > std::numeric_limits<int>::max()) {
return false;
}
*out = (int)lout;
return true;
}

Expand All @@ -70,8 +79,9 @@ bool XmlValue::read(const char *path, long *out) const {
return false;
}

*out = atol(value->text().c_str());
return true;
char * e;
*out = strtol(value->text().c_str(), &e, 10);
return (*e == '\0');
}

bool XmlValue::read(const char *path, double *out) const {
Expand All @@ -80,8 +90,9 @@ bool XmlValue::read(const char *path, double *out) const {
return false;
}

*out = atof(value->text().c_str());
return true;
char * e;
*out = strtod(value->text().c_str(), &e);
return (*e == '\0');
}

bool XmlValue::read(const char *path, bool *out) const {
Expand All @@ -90,8 +101,9 @@ bool XmlValue::read(const char *path, bool *out) const {
return false;
}

*out = (atoi(value->text().c_str()) != 0);
return true;
char * e;
*out = (strtol(value->text().c_str(), &e, 10) != 0);
return (*e == '\0');
}

bool XmlValue::readB64(const char *path, unsigned char *data,
Expand Down

0 comments on commit 4e19edf

Please sign in to comment.