r93221 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r93220‎ | r93221 | r93222 >
Date:17:32, 26 July 2011
Author:platonides
Status:ok
Tags:
Comment:
Move in_buff from the heap to the stack
Modified paths:
  • /trunk/debs/squid/redirector.c (modified) (history)

Diff [purge]

Index: trunk/debs/squid/redirector.c
@@ -54,8 +54,7 @@
5555 char buff[MAX_BUFF];
5656 setbuf(stdout, NULL);
5757
58 - struct IN_BUFF *in_buff = NULL;
59 - in_buff = (struct IN_BUFF *)malloc(sizeof(struct IN_BUFF));
 58+ struct IN_BUFF in_buff;
6059 pattern = "^http:\\/\\/(\\w+)\\.wikipedia\\.org[:\\d]*\\/(.*)";
6160 pcre_extra *pe;
6261
@@ -81,17 +80,17 @@
8281
8382 while(fgets(buff, MAX_BUFF, stdin) != NULL) {
8483
85 - if (load_in_buff(buff, in_buff) != 0) {
 84+ if (load_in_buff(buff, &in_buff) != 0) {
8685 fprintf(stderr, "Error loading data %s\n", buff);
8786 continue;
8887 }
8988
90 - subject_length = (int)strlen(in_buff->url);
 89+ subject_length = (int)strlen(in_buff.url);
9190
9291 rc = pcre_exec(
9392 re, /* the compiled pattern */
9493 pe, /* no extra data - we didn't study the pattern */
95 - in_buff->url, /* the subject string */
 94+ in_buff.url, /* the subject string */
9695 subject_length, /* the length of the subject */
9796 0, /* start at offset 0 in the subject */
9897 0, /* default options */
@@ -101,7 +100,7 @@
102101 if (rc < 0) {
103102 switch(rc) {
104103 case PCRE_ERROR_NOMATCH:
105 - printf("%s\n", in_buff->url);
 104+ printf("%s\n", in_buff.url);
106105 fflush(stdout);
107106
108107 break;
@@ -117,7 +116,7 @@
118117
119118 for (i = 0; i < rc; i++) {
120119
121 - char *substring_start = in_buff->url + ovector[2*i];
 120+ char *substring_start = in_buff.url + ovector[2*i];
122121 int substring_length = ovector[2*i+1] - ovector[2*i];
123122 if (i == 1) {
124123 if (substring_length >= sizeof(lang)) {

Status & tagging log