Skip to content

Commit

Permalink
Merge pull request redis#72 from chipdude/master
Browse files Browse the repository at this point in the history
Fix self-test of connect error on Linux; merge duplicated string (DRY)
  • Loading branch information
pietern committed Dec 20, 2011
2 parents 95e8338 + 56ae8aa commit d5d8843
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
11 changes: 6 additions & 5 deletions hiredis.c
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
default:
/* Try to detect printf format */
{
static const char intfmts[] = "diouxX";
char _format[16];
const char *_p = c+1;
size_t _l = 0;
Expand All @@ -774,7 +775,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
va_copy(_cpy,ap);

/* Integer conversion (without modifiers) */
if (strchr("diouxX",*_p) != NULL) {
if (strchr(intfmts,*_p) != NULL) {
va_arg(ap,int);
goto fmt_valid;
}
Expand All @@ -788,7 +789,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Size: char */
if (_p[0] == 'h' && _p[1] == 'h') {
_p += 2;
if (*_p != '\0' && strchr("diouxX",*_p) != NULL) {
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,int); /* char gets promoted to int */
goto fmt_valid;
}
Expand All @@ -798,7 +799,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Size: short */
if (_p[0] == 'h') {
_p += 1;
if (*_p != '\0' && strchr("diouxX",*_p) != NULL) {
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,int); /* short gets promoted to int */
goto fmt_valid;
}
Expand All @@ -808,7 +809,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Size: long long */
if (_p[0] == 'l' && _p[1] == 'l') {
_p += 2;
if (*_p != '\0' && strchr("diouxX",*_p) != NULL) {
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,long long);
goto fmt_valid;
}
Expand All @@ -818,7 +819,7 @@ int redisvFormatCommand(char **target, const char *format, va_list ap) {
/* Size: long */
if (_p[0] == 'l') {
_p += 1;
if (*_p != '\0' && strchr("diouxX",*_p) != NULL) {
if (*_p != '\0' && strchr(intfmts,*_p) != NULL) {
va_arg(ap,long);
goto fmt_valid;
}
Expand Down
5 changes: 3 additions & 2 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ static void test_format_commands(void) {
FLOAT_WIDTH_TEST(double);

test("Format command with invalid printf format: ");
len = redisFormatCommand(&cmd,"key:%08p %b",1234,"foo",3);
len = redisFormatCommand(&cmd,"key:%08p %b",(void*)1234,"foo",3);
test_cond(len == -1);

const char *argv[3];
Expand Down Expand Up @@ -283,7 +283,8 @@ static void test_blocking_connection_errors(void) {
test("Returns error when host cannot be resolved: ");
c = redisConnect((char*)"idontexist.local", 6379);
test_cond(c->err == REDIS_ERR_OTHER &&
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0);
(strcmp(c->errstr,"Name or service not known") == 0 ||
strcmp(c->errstr,"Can't resolve: idontexist.local") == 0));
redisFree(c);

test("Returns error when the port is not open: ");
Expand Down

0 comments on commit d5d8843

Please sign in to comment.