Skip to content

Commit

Permalink
fix segfault
Browse files Browse the repository at this point in the history
Signed-off-by: Sy Tran Dung <13009812+sytranvn@users.noreply.github.com>
  • Loading branch information
sytranvn committed Oct 4, 2023
1 parent cd551e3 commit b4c8de1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ build/
_deps/
CMakeCache.txt
CMakeFiles/
test/Testing/
Testing/
# Prerequisites
*.d

Expand Down
1 change: 1 addition & 0 deletions src/shared/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ void str_to_buff(const char *str, std::uint8_t *&buff, std::size_t &len) {
unsigned int val;
std::stringstream *ss = new std::stringstream;
size_t l = strlen(str);
len = l / 2;
buff = (uint8_t *)malloc(sizeof(char) * l / 2);
for (int i = 0; i < strlen(str); i += 2) {
(*ss) << str[i];
Expand Down
5 changes: 3 additions & 2 deletions test/ch_1_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
TEST(ch_1, b64_str) {

char *st = (char *)("49276d206b696c6c696e6720796f757220627261696e206c696b6520"
"6120706f69736f6e6f7573206d757368726f6f6d");
"6120706f69736f6e6f7573206d757368726f6f6d\0");
char *expect =
(char *)"SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11"
"c2hyb29t";
"c2hyb29t\0";
char *out;
b64_str(st, &out);

// printf("%s\n", out);
ASSERT_STREQ(expect, out);

free(out);
Expand Down
2 changes: 1 addition & 1 deletion test/common_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
TEST(common, str_to_buff) {
char *str =
(char *)("49276d206b696c6c696e6720796f757220627261696e206c696b6520"
"6120706f69736f6e6f7573206d757368726f6f6d");
"6120706f69736f6e6f7573206d757368726f6f6d\0");
std::size_t len;
std::uint8_t *buff;
str_to_buff(str, buff, len);
Expand Down

0 comments on commit b4c8de1

Please sign in to comment.