-
Notifications
You must be signed in to change notification settings - Fork 278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
more fixes #2508
Merged
Merged
more fixes #2508
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c91a51f
make conversions explicit
neheb 412fd7f
use upper() function
neheb 8c1e79d
fix memory leak
neheb 4748c8b
replace localtime with _s/_r variant
neheb 38e4dbe
explicit conversion
neheb 4c36e2e
fix wrong snprintf format
neheb fadade3
replace array with vector
neheb f921e88
use count_if
neheb 2722e00
use std::replace
neheb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
|
@@ -823,8 +823,7 @@ bool LoaderXmpJpeg::readDimensions() { | |
DataBuf decodeHex(const byte* src, size_t srcSize) { | ||
// create decoding table | ||
byte invalid = 16; | ||
std::array<byte, 256> decodeHexTable; | ||
decodeHexTable.fill(invalid); | ||
auto decodeHexTable = std::vector<byte>(256, invalid); | ||
for (byte i = 0; i < 10; i++) | ||
decodeHexTable[static_cast<byte>('0') + i] = i; | ||
for (byte i = 0; i < 6; i++) | ||
|
@@ -861,21 +860,15 @@ DataBuf decodeHex(const byte* src, size_t srcSize) { | |
const char encodeBase64Table[64 + 1] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; | ||
|
||
DataBuf decodeBase64(const std::string& src) { | ||
const size_t srcSize = src.size(); | ||
|
||
// create decoding table | ||
unsigned long invalid = 64; | ||
std::array<unsigned long, 256> decodeBase64Table; | ||
decodeBase64Table.fill(invalid); | ||
auto decodeBase64Table = std::vector<unsigned long>(256, invalid); | ||
for (unsigned long i = 0; i < 64; i++) | ||
decodeBase64Table[static_cast<unsigned char>(encodeBase64Table[i])] = i; | ||
|
||
// calculate dest size | ||
unsigned long validSrcSize = 0; | ||
for (unsigned long srcPos = 0; srcPos < srcSize; srcPos++) { | ||
if (decodeBase64Table[static_cast<unsigned char>(src[srcPos])] != invalid) | ||
validSrcSize++; | ||
} | ||
auto validSrcSize = static_cast<unsigned long>( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we use |
||
std::count_if(src.begin(), src.end(), [=](unsigned char c) { return decodeBase64Table.at(c) != invalid; })); | ||
if (validSrcSize > ULONG_MAX / 3) | ||
return {}; // avoid integer overflow | ||
const unsigned long destSize = (validSrcSize * 3) / 4; | ||
|
@@ -888,7 +881,7 @@ DataBuf decodeBase64(const std::string& src) { | |
// decode | ||
for (unsigned long srcPos = 0, destPos = 0; destPos < destSize;) { | ||
unsigned long buffer = 0; | ||
for (int bufferPos = 3; bufferPos >= 0 && srcPos < srcSize; srcPos++) { | ||
for (int bufferPos = 3; bufferPos >= 0 && srcPos < src.size(); srcPos++) { | ||
unsigned long srcValue = decodeBase64Table[static_cast<unsigned char>(src[srcPos])]; | ||
if (srcValue == invalid) | ||
continue; | ||
|
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the benefit of doing it this way?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IIRC bytes it a shadowed declaration. because of copy elision, it's the same.