Skip to content

Commit

Permalink
Work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusNi committed Nov 12, 2024
1 parent e8bca27 commit 2bcc253
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/adapters/pnp/PnpAgent.c
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ int main(int argc, char *argv[])
snprintf(g_productInfo, sizeof(g_productInfo), g_productInfoTemplate, g_modelVersion, OSCONFIG_VERSION, osName, osVersion,
cpuType, cpuVendor, cpuModel, totalMemory, freeMemory, kernelName, kernelRelease, kernelVersion, productVendor, productName);

if (NULL != (encodedProductInfo = UrlEncode(g_productInfo, sizeof(g_productInfo))))
if (NULL != (encodedProductInfo = UrlEncode(g_productInfo)))
{
if (strlen(encodedProductInfo) >= sizeof(g_productInfo))
{
Expand Down
2 changes: 1 addition & 1 deletion src/common/commonutils/FileUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ int CheckSmallFileContainsText(const char* fileName, const char* text, char** re

if (NULL != (contents = LoadStringFromFile(fileName, false, log)))
{
contentsLength = strlen(text);
contentsLength = strlen(contents);

if (0 == strncmp(contents, text, (textLength <= contentsLength) ? textLength : contentsLength))
{
Expand Down
14 changes: 7 additions & 7 deletions src/common/commonutils/UrlUtils.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

#include "Internal.h"

char* UrlEncode(const char* target, size_t targetSize)
char* UrlEncode(const char* target)
{
size_t i = 0, j = 0;
size_t targetSize = 0, i = 0, j = 0;
int encodedLength = 0;
char* encodedTarget = NULL;

if ((NULL == target) || (0 == targetSize))
if ((NULL == target) || (0 == (targetSize = strlen(target))))
{
return NULL;
}
Expand Down Expand Up @@ -43,14 +43,14 @@ char* UrlEncode(const char* target, size_t targetSize)
return encodedTarget;
}

char* UrlDecode(const char* target, size_t targetSize)
char* UrlDecode(const char* target)
{
size_t i = 0, j = 0;
size_t targetSize = 0, i = 0, j = 0;
char buffer[3] = {0};
unsigned int value = 0;
char* decodedTarget = NULL;

if ((NULL == target) || (0 == targetSize))
if ((NULL == target) || (0 == (targetSize = strlen(target))))
{
return NULL;
}
Expand Down Expand Up @@ -78,7 +78,7 @@ char* UrlDecode(const char* target, size_t targetSize)
buffer[2] = 0;

sscanf(buffer, "%x", &value);
snprintf(&decodedTarget[i], targetSize - i, "%c", value);
sprintf(&decodedTarget[i], "%c", value);
}

j += sizeof(buffer);
Expand Down
10 changes: 4 additions & 6 deletions src/common/tests/CommonUtilsUT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1094,19 +1094,17 @@ TEST_F(CommonUtilsTest, UrlEncodeDecode)

for (int i = 0; i < testUrlsSize; i++)
{
EXPECT_NE(nullptr, url = UrlEncode((char*)testUrls[i].decoded, strlen(testUrls[i].decoded)));
EXPECT_NE(nullptr, url = UrlEncode((char*)testUrls[i].decoded));
EXPECT_STREQ(url, testUrls[i].encoded);
FREE_MEMORY(url);

EXPECT_NE(nullptr, url = UrlDecode((char*)testUrls[i].encoded, strlen(testUrls[i].encoded)));
EXPECT_NE(nullptr, url = UrlDecode((char*)testUrls[i].encoded));
EXPECT_STREQ(url, testUrls[i].decoded);
FREE_MEMORY(url);
}

EXPECT_EQ(nullptr, url = UrlEncode(nullptr, 1));
EXPECT_EQ(nullptr, url = UrlDecode(nullptr, 1));
EXPECT_EQ(nullptr, url = UrlEncode(nullptr, 0));
EXPECT_EQ(nullptr, url = UrlDecode(nullptr, 0));
EXPECT_EQ(nullptr, url = UrlEncode(nullptr));
EXPECT_EQ(nullptr, url = UrlDecode(nullptr));
}

TEST_F(CommonUtilsTest, LockUnlockFile)
Expand Down

0 comments on commit 2bcc253

Please sign in to comment.