httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Marc Slemko <ma...@worldgate.com>
Subject Re: strncpy is evil
Date Tue, 23 Dec 1997 15:19:04 GMT
Call it ap_strncpy and define it well to always null terminate and be
happy.

On Tue, 23 Dec 1997, Dean Gaudet wrote:

> On Tue, 23 Dec 1997, Dean Gaudet wrote:
> 
> > With current code I get 98.56 req/s.
> > With the patch below I get 138.94 req/s.
> 
> With the patch below I get 186.89 req/s.
> 
> Profiling shows me that table_set on average has to call strcasecmp() 10
> times... because of add_common_vars and similar ilk.  There's a bunch of
> room for speedup there I'm sure.
> 
> Dean
> 
> Index: main/util.c
> ===================================================================
> RCS file: /export/home/cvs/apachen/src/main/util.c,v
> retrieving revision 1.78
> diff -u -r1.78 util.c
> --- util.c	1997/12/19 14:30:12	1.78
> +++ util.c	1997/12/23 10:58:01
> @@ -1624,3 +1624,15 @@
>      return (time1 - time0);
>  }
>  #endif
> +
> +char *strncpy(char *dst, const char *src, size_t len)
> +{
> +    char *d = dst;
> +
> +    for(;;) {
> +	if (!len) break;
> +	if (!(*d++ = *src++)) break;
> +	--len;
> +    }
> +    return dst;
> +}
> Index: modules/standard/mod_include.c
> ===================================================================
> RCS file: /export/home/cvs/apachen/src/modules/standard/mod_include.c,v
> retrieving revision 1.59
> diff -u -r1.59 mod_include.c
> --- mod_include.c	1997/12/22 21:53:17	1.59
> +++ mod_include.c	1997/12/23 10:58:06
> @@ -96,6 +96,9 @@
>  #define SIZEFMT_BYTES 0
>  #define SIZEFMT_KMG 1
>  
> +#ifndef WASTE_OF_TIME
> +#define chdir_file(x)
> +#endif
>  
>  /* ------------------------ Environment function -------------------------- */
>  
> @@ -108,18 +111,23 @@
>      char *t;
>      time_t date = r->request_time;
>  
> +#ifdef WASTE_OF_TIME
>      table_set(e, "DATE_LOCAL", ht_time(r->pool, date, timefmt, 0));
>      table_set(e, "DATE_GMT", ht_time(r->pool, date, timefmt, 1));
>      table_set(e, "LAST_MODIFIED",
>                ht_time(r->pool, r->finfo.st_mtime, timefmt, 0));
> +#endif
>      table_set(e, "DOCUMENT_URI", r->uri);
>      table_set(e, "DOCUMENT_PATH_INFO", r->path_info);
>  #ifndef WIN32
> +#ifdef WASTE_OF_TIME
>      pw = getpwuid(r->finfo.st_uid);
>      if (pw) {
>          table_set(e, "USER_NAME", pw->pw_name);
>      }
> -    else {
> +    else
> +#endif
> +    {
>          char uid[16];
>          ap_snprintf(uid, sizeof(uid), "user#%lu",
>                      (unsigned long) r->finfo.st_uid);
> @@ -912,10 +920,12 @@
>              parse_string(r, tag_val, parsed_string, MAX_STRING_LEN, 0);
>              strncpy(tf, parsed_string, MAX_STRING_LEN - 1);
>              tf[MAX_STRING_LEN - 1] = '\0';
> +#ifdef WASTE_OF_TIME
>              table_set(env, "DATE_LOCAL", ht_time(r->pool, date, tf, 0));
>              table_set(env, "DATE_GMT", ht_time(r->pool, date, tf, 1));
>              table_set(env, "LAST_MODIFIED",
>                        ht_time(r->pool, r->finfo.st_mtime, tf, 0));
> +#endif
>          }
>          else if (!strcmp(tag, "sizefmt")) {
>              parse_string(r, tag_val, parsed_string, MAX_STRING_LEN, 0);
> 


Mime
View raw message