|
Neohapsis is currently accepting applications for employment. For more information, please visit our website www.neohapsis.com or email hr@neohapsis.com |
(no subject)
From: Tom Cosgrove (tom.cosgrove
arches-consulting.com)
Date: Mon Apr 03 2006 - 08:36:19 CDT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
>>> Alexey Dobriyan 3-Apr-06 13:11 >>>
>
> * mem_alloc + memset => calloc
> * ALLOC + BZERO => calloc
> * Remove ALLOC and BZERO for being trivial wrappers.
>
> Index: lib/libc/rpc/svc.c
> ===================================================================
> RCS file: /cvs/src/lib/libc/rpc/svc.c,v
> retrieving revision 1.21
> diff -u -p -r1.21 svc.c
> --- lib/libc/rpc/svc.c 2005/12/21 01:40:22 1.21
> +++ lib/libc/rpc/svc.c 2006/04/03 09:25:13
> :
> : [skip one chunk]
> :
> 
-173,8 +172,8 
svc_fd_insert(int sock)
>
> bytes = howmany(sock + 128, NFDBITS) * sizeof(fd_mask);
> /* realloc() would be nicer but it gets tricky... */
> - if ((fds = (fd_set *)mem_alloc(bytes)) != NULL) {
> - memset(fds, 0, bytes);
> + fds = calloc(howmany(sock + 128, NFDBITS), sizeof(fd_mask));
> + if (fds) {
> memcpy(fds, __svc_fdset,
> howmany(__svc_fdsetsize, NFDBITS) * sizeof(fd_mask));
> if (__svc_fdset != &svc_fdset)
Don't you think something like the following (untested) would be better?
Index: svc.c
===================================================================
RCS file: /home/OpenBSD/cvs/src/lib/libc/rpc/svc.c,v
retrieving revision 1.21
diff -u -r1.21 svc.c
--- svc.c 21 Dec 2005 01:40:22 -0000 1.21
+++ svc.c 3 Apr 2006 13:33:12 -0000

-169,18 +169,17 
}
if (sock + 1 > __svc_fdsetsize) {
fd_set *fds;
- size_t bytes;
+ size_t n;
- bytes = howmany(sock + 128, NFDBITS) * sizeof(fd_mask);
+ n = howmany(sock + 128, NFDBITS);
/* realloc() would be nicer but it gets tricky... */
- if ((fds = (fd_set *)mem_alloc(bytes)) != NULL) {
- memset(fds, 0, bytes);
+ if ((fds = calloc(n, sizeof(fd_mask))) != NULL) {
memcpy(fds, __svc_fdset,
howmany(__svc_fdsetsize, NFDBITS) * sizeof(fd_mask));
if (__svc_fdset != &svc_fdset)
free(__svc_fdset);
__svc_fdset = fds;
- __svc_fdsetsize = bytes / sizeof(fd_mask);
+ __svc_fdsetsize = n;
}
}
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]