r71849 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r71848‎ | r71849 | r71850 >
Date:11:16, 28 August 2010
Author:platonides
Status:deferred
Tags:
Comment:
Be more robust in case we are given commands with wrong or missing parameters.
Modified paths:
  • /trunk/extensions/PoolCounter/daemon/locks.c (modified) (history)

Diff [purge]

Index: trunk/extensions/PoolCounter/daemon/locks.c
@@ -26,6 +26,22 @@
2727 #define DOUBLE_LLIST_DEL(this) do { (this)->prev->next = (this)->next; (this)->next->prev = (this)->prev; } while (0)
2828 #define DOUBLE_LLIST_ADD(parent,child) do { (child)->prev = (parent)->prev; (child)->next = (child)->prev->next /* parent */; (parent)->prev->next = (child); (parent)->prev = (child); } while(0);
2929
 30+/* Converts a numeric text into an unsigned integer.
 31+ * Returns 0 if it's a NULL pointer or not a natural.
 32+ */
 33+unsigned atou(char const* astext) {
 34+ int num = 0;
 35+ if (!astext) return 0;
 36+
 37+ while ( *astext ) {
 38+ if ( *astext < '0' ) return 0;
 39+ if ( *astext > '9' ) return 0;
 40+ num = num * 10 + *astext - '0';
 41+ astext++;
 42+ }
 43+ return num;
 44+}
 45+
3046 char* process_line(struct client_data* cli_data, char* line, int line_len) {
3147 struct locks* l = &cli_data->client_locks;
3248
@@ -37,10 +53,14 @@
3854 int for_anyone = line[6] != ' ';
3955
4056 char* key = strtok( line + 7 + for_anyone, " " );
41 - int workers = atoi( strtok(NULL, " ") );
42 - int maxqueue = atoi( strtok(NULL, " ") );
43 - int timeout = atoi( strtok(NULL, " ") );
 57+ unsigned workers = atou( strtok(NULL, " ") );
 58+ unsigned maxqueue = atou( strtok(NULL, " ") );
 59+ unsigned timeout = atou( strtok(NULL, " ") );
4460
 61+ if ( !key || !workers || !maxqueue || !timeout ) {
 62+ return "ERROR BAD_SYNTAX\n";
 63+ }
 64+
4565 uint32_t hash_value = hash( key, strlen( key ), 0 );
4666 struct PoolCounter* pCounter;
4767 pCounter = hashtable_find( primary_hashtable, hash_value, key );

Status & tagging log