Skip to content

INTERNAL: Return an empty string if the value length is 0 #363

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions libmemcached/string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,6 @@ memcached_return_t memcached_string_append(memcached_string_st *string,

char *memcached_string_c_copy(memcached_string_st *string)
{
if (not memcached_string_length(string))
return NULL;

char *c_ptr= static_cast<char *>(libmemcached_malloc(string->root, (memcached_string_length(string)+1) * sizeof(char)));

if (not c_ptr)
Expand Down
9 changes: 6 additions & 3 deletions tests/mem_functions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3054,17 +3054,19 @@ static test_return_t user_supplied_bug15(memcached_st *memc)
&length, &flags, &rc);

test_compare(MEMCACHED_SUCCESS, rc);
test_false(value);
test_false(value == NULL);
test_zero(length);
test_zero(flags);
free(value);

value= memcached_get(memc, test_literal_param("mykey"),
&length, &flags, &rc);

test_compare(MEMCACHED_SUCCESS, rc);
test_true(value == NULL);
test_true(value != NULL);
test_zero(length);
test_zero(flags);
free(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.
์—ฌ๊ธฐ test์—์„œ memcached_get() 2ํšŒ ์ˆ˜ํ–‰ํ•˜๋Š” ์ด์œ ๋Š” ๋ฌด์—‡์ผ๊นŒ์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋ชจ๋ฅด๊ฒ ์œผ๋‚˜ ํฐ ์˜๋ฏธ๋Š” ์—†๋Š” ๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.

libmemcached์—์„œ ํ•ด๋‹น ๋ฒ„๊ทธ์— ๋Œ€ํ•œ ์„ค๋ช…์€ ๋”ฐ๋กœ ์—†์—ˆ์Šต๋‹ˆ๋‹ค.

}

return TEST_SUCCESS;
Expand All @@ -3085,9 +3087,10 @@ static test_return_t user_supplied_bug16(memcached_st *memc)
&length, &flags, &rc);

test_compare(MEMCACHED_SUCCESS, rc);
test_true(value == NULL);
test_true(value != NULL);
test_zero(length);
test_compare(flags, UINT32_MAX);
free(value);

return TEST_SUCCESS;
}
Expand Down
8 changes: 6 additions & 2 deletions tests/memcat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ static test_return_t cat_test(void *)
memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0));

memcached_return_t rc;
test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
char *value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);

test_true(exec_cmdline(executable, args));

test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.
์—ฌ๊ธฐ cat_test๋Š” ์–ด๋–ค ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ธ๊ฐ€์š”?

Copy link
Collaborator Author

@ing-eoking ing-eoking Mar 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ด ํ…Œ์ŠคํŠธ๋Š” arcus-c-client์—์„œ ํ…Œ์ŠคํŠธ ์šฉ๋„๋กœ ์ œ๊ณตํ•˜๋Š” ์ผ์ข…์˜ ์‰˜ ๋ช…๋ น์–ด๋“ค์„ ๋‹ค๋ฃจ๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค.
์ด ๋ช…๋ น์–ด๋“ค์€ memcached์— ์ €์žฅ๋œ Key-Value ๋ฐ์ดํ„ฐ๋ฅผ telnet์„ ์‚ฌ์šฉํ•˜์ง€ ์•Š๊ณ ๋„ ๊ฐ„ํŽธํ•˜๊ฒŒ ์กฐํšŒํ•  ์ˆ˜ ์žˆ๊ฒŒ ๋„์™€์ค๋‹ˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด, C Client๋ฅผ ์„ค์น˜ํ•œ ํ›„์— memcat -s SERVER_ADDRESS key ๋ช…๋ น์–ด๋ฅผ ์‹คํ–‰ํ•˜๋ฉด,
(SERVER_ADDRESS = memcached ์„œ๋ฒ„ ์ฃผ์†Œ)
memcached ์„œ๋ฒ„์—์„œ key๋ผ๋Š” ์•„์ดํ…œ์˜ value ๊ฐ’์ด ์ถœ๋ ฅ๋ฉ๋‹ˆ๋‹ค.


memcached_free(memc);

Expand Down
4 changes: 3 additions & 1 deletion tests/memdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,10 @@ static test_return_t FOUND_test(void *)
memcached_set(memc, test_literal_param("foo2"), 0, 0, 0, 0));

memcached_return_t rc;
test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
char *value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์—ฌ๊ธฐ๋„ ์งˆ๋ฌธ์ž…๋‹ˆ๋‹ค.
FOUND_test๋Š” ์–ด๋–ค ํ…Œ์ŠคํŠธ๋ฅผ ํ•˜๋Š” ๊ฒƒ์ธ๊ฐ€์š”?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ•ด๋‹น ํ…Œ์ŠคํŠธ ๋˜ํ•œ ์œ„์˜ cat_test์™€ ๋™์ผํ•ฉ๋‹ˆ๋‹ค.


test_true(exec_cmdline(executable, args));

Expand Down
8 changes: 6 additions & 2 deletions tests/memexist.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,17 @@ static test_return_t exist_test(void *)
memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0));

memcached_return_t rc;
test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
char *value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);

test_true(exec_cmdline(executable, args));

test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);

memcached_free(memc);

Expand Down
4 changes: 3 additions & 1 deletion tests/memrm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ static test_return_t rm_test(void *)
memcached_set(memc, test_literal_param("foo"), 0, 0, 0, 0));

memcached_return_t rc;
test_null(memcached_get(memc, test_literal_param("foo"), 0, 0, &rc));
char *value= memcached_get(memc, test_literal_param("foo"), 0, 0, &rc);
test_compare(MEMCACHED_SUCCESS, rc);
test_true(value != NULL);
free(value);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ…Œ์ŠคํŠธ ์ฝ”๋“œ๋ฅผ ๋ณด๋‹ˆ, ์ผ๊ด€๋˜๊ฒŒ
value length๊ฐ€ 0์ด๋ฉด NULL ๋ฆฌํ„ดํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋˜์–ด ์žˆ๋„ค์š”.


test_true(exec_cmdline(executable, args));

Expand Down