[Asterisk-code-review] Change in asterisk[master]: cel_pgsql: Fix schema query for get columns name

Mark Michelson (Code Review) asteriskteam at digium.com
Wed Apr 15 14:49:07 CDT 2015


Mark Michelson has posted comments on this change.

Change subject: cel_pgsql: Fix schema query for get columns name
......................................................................


Patch Set 1:

(2 comments)

https://gerrit.asterisk.org/#/c/120/1/cel/cel_pgsql.c
File cel/cel_pgsql.c:

Line 562: 			/* Escape special characters in schemaname */
        : 			if (strchr(schemaname, '\\') || strchr(schemaname, '\'')) {
        : 				char *tmp = schemaname, *ptr;
        : 
        : 				ptr = schemaname = ast_alloca(strlen(tmp) * 2 + 1);
        : 				for (; *tmp; tmp++) {
        : 					if (strchr("\\'", *tmp)) {
        : 						*ptr++ = *tmp;
        : 					}
        : 					*ptr++ = *tmp;
        : 				}
        : 				*ptr = '\0';
        : 			}
        : 			/* Escape special characters in tablename */
        : 			if (strchr(tablename, '\\') || strchr(tablename, '\'')) {
        : 				char *tmp = tablename, *ptr;
        : 
        : 				ptr = tablename = ast_alloca(strlen(tmp) * 2 + 1);
        : 				for (; *tmp; tmp++) {
        : 					if (strchr("\\'", *tmp)) {
        : 						*ptr++ = *tmp;
        : 					}
        : 					*ptr++ = *tmp;
        : 				}
        : 				*ptr = '\0';
        : 			}
These two sections are exactly the same except for the fact that one operates on "schemaname" and the other operates on "tablename". I know that you copied this example from other Asterisk pgsql code, but for this new addition, I suggest writing a separate function instead of repeating the same code.


Line 612: 			if (atoi(flen) == -1) {
        : 				/* For varchar columns, the maximum length is encoded in a different field */
        : 				flen = PQgetvalue(result, i, 5);
        : 			}
Please use sscanf() instead of atoi.


-- 
To view, visit https://gerrit.asterisk.org/120
To unsubscribe, visit https://gerrit.asterisk.org/settings

Gerrit-MessageType: comment
Gerrit-Change-Id: I691fd2cbc277fcba10e615f5884f8de5d8152f2c
Gerrit-PatchSet: 1
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Owner: Rodrigo Ramirez Norambuena <decipher.hk at gmail.com>
Gerrit-Reviewer: Mark Michelson <mmichelson at digium.com>
Gerrit-HasComments: Yes



More information about the asterisk-code-review mailing list