-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix segfault pertaining to sliding window bounds (#113)
- Loading branch information
Showing
5 changed files
with
27 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,24 @@ | ||
#include <cmath> | ||
|
||
#include "voidstar/size2str.h" | ||
|
||
#include <cmath> | ||
|
||
/// 991337 --> "991,337" | ||
std::string size2str(size_t size) { | ||
const auto digits = std::ceil(std::log10(size)); | ||
const auto nonits = static_cast<size_t>(std::ceil(digits / 3) -1); | ||
std::string str(static_cast<size_t>(digits)+nonits, '*'); | ||
const auto nonits = static_cast<size_t>(std::ceil(digits / 3) - 1); | ||
std::string str(static_cast<size_t>(digits) + nonits, '*'); | ||
|
||
int written = 0; | ||
for (size_t pos = str.length()-1; pos!=0; pos--) { | ||
for (size_t pos = str.length() - 1; pos != 0; pos--) { | ||
if (written != 0 && written % 3 == 0) { | ||
str[pos] = '_'; | ||
written = 0; | ||
continue; | ||
} | ||
str[pos] = static_cast<char>('0' + size%10); | ||
str[pos] = static_cast<char>('0' + size % 10); | ||
size /= 10; | ||
written++; | ||
} | ||
if (size != 0) | ||
str[0] = static_cast<char>('0' + size); | ||
if (size != 0) str[0] = static_cast<char>('0' + size); | ||
return str; | ||
} |