r93219 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93218‎ | r93219 | r93220 >
Date:17:31, 26 July 2011
Author:platonides
Status:ok
Tags:
Comment:
Why so many string copies?
References are your friends!
Modified paths:
  • /trunk/debs/squid/redirector.c (modified) (history)

Diff [purge]

Index: trunk/debs/squid/redirector.c
@@ -9,6 +9,7 @@
1010 */
1111
1212 #include <stdio.h>
 13+#include <string.h>
1314 #include <stdlib.h>
1415 #include <string.h>
1516 #include <malloc.h>
@@ -25,23 +26,15 @@
2627 };
2728
2829 int load_in_buff(char *buff, struct IN_BUFF *in_buff) {
29 - int converted;
30 -
31 - strcpy(in_buff->url, "");
32 - strcpy(in_buff->src_address, "");
33 - strcpy(in_buff->ident, "");
34 - strcpy(in_buff->method, "");
 30+ in_buff->url = strtok(buff, " ");
 31+ in_buff->src_address = strtok(NULL, " ");
 32+ in_buff->ident= strtok(NULL, " ");
 33+ in_buff->method= strtok(NULL, " \n");;
3534
36 - converted = sscanf(buff, "%s %s %s %s\n", in_buff->url, in_buff->src_address, in_buff->ident, in_buff->method);
37 -
38 - if(converted != 4) {
 35+ if (!in_buff->src_address || !in_buff->ident || !in_buff->method) {
3936 return 1;
4037 }
4138
42 - if(strcmp(in_buff->src_address, "") == 0) {
43 - return 1;
44 - }
45 -
4639 if(strlen(in_buff->url) <= 4) {
4740 return 1;
4841 }
@@ -63,10 +56,6 @@
6457
6558 struct IN_BUFF *in_buff = NULL;
6659 in_buff = (struct IN_BUFF *)malloc(sizeof(struct IN_BUFF));
67 - in_buff->url = malloc(MAX_BUFF);
68 - in_buff->src_address = malloc(MAX_BUFF);
69 - in_buff->ident = malloc(MAX_BUFF);
70 - in_buff->method = malloc(MAX_BUFF);
7160 pattern = "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/(.*)";
7261 pcre_extra *pe;
7362

Status & tagging log