[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: svn commit: r35050 - trunk/subversion/libsvn_subr

From: Julian Foad <julianfoad_at_btopenworld.com>
Date: Fri, 09 Jan 2009 11:55:36 +0000

Greg Stein wrote:
> eh? why "void *" in this case? The proper type would seem to be
> "unsigned char *" (and still const, of course)

The function is intended to operate on an arbitrary block of memory,
starting at a given address and going on for the given number of bytes.
"void *" is the canonical type for the address of an arbitrary block of
memory. Using a specific type like "unsigned char *" is just asking
callers to have to do type-casting for no benefit. No?

- Julian

> On Tue, Jan 6, 2009 at 10:15, Julian Foad <julianfoad_at_btopenworld.com> wrote:
> > Author: julianfoad
> > Date: Tue Jan 6 10:15:33 2009
> > New Revision: 35050
> >
> > Log:
> > Tweak a local function signature to avoid the need for a type cast. (This
> > particular type cast was casting away "const" though it need not have done.)
> >
> > * subversion/libsvn_subr/svn_base64.c
> > (encode_bytes): Take "void *" instead of "char *" input data.
> > (svn_base64_from_checksum): Remove a type cast in calling encode_bytes().
> >
> > Modified:
> > trunk/subversion/libsvn_subr/svn_base64.c
> >
> > Modified: trunk/subversion/libsvn_subr/svn_base64.c
> > URL: http://svn.collab.net/viewvc/svn/trunk/subversion/libsvn_subr/svn_base64.c?pathrev=35050&r1=35049&r2=35050
> > ==============================================================================
> > --- trunk/subversion/libsvn_subr/svn_base64.c Tue Jan 6 09:11:11 2009 (r35049)
> > +++ trunk/subversion/libsvn_subr/svn_base64.c Tue Jan 6 10:15:33 2009 (r35050)
> > @@ -68,12 +68,12 @@ encode_group(const unsigned char *in, ch
> > initialize *INBUFLEN and *LINELEN to 0. Output will be appended to
> > STR. Include newlines every so often if BREAK_LINES is true. */
> > static void
> > -encode_bytes(svn_stringbuf_t *str, const char *data, apr_size_t len,
> > +encode_bytes(svn_stringbuf_t *str, const void *data, apr_size_t len,
> > unsigned char *inbuf, int *inbuflen, int *linelen,
> > svn_boolean_t break_lines)
> > {
> > char group[4];
> > - const char *p = data, *end = data + len;
> > + const char *p = data, *end = p + len;
> >
> > /* Keep encoding three-byte groups until we run out. */
> > while (*inbuflen + (end - p) >= 3)
> > @@ -381,10 +381,7 @@ svn_base64_from_checksum(svn_checksum_t
> > int ingrouplen = 0, linelen = 0;
> > checksum_str = svn_stringbuf_create("", pool);
> >
> > - /* This cast is safe because we know encode_bytes does a memcpy and
> > - * does an implicit unsigned char * cast.
> > - */
> > - encode_bytes(checksum_str, (char*)checksum->digest,
> > + encode_bytes(checksum_str, checksum->digest,
> > svn_checksum_size(checksum), ingroup, &ingrouplen,
> > &linelen, TRUE);
> > encode_partial_group(checksum_str, ingroup, ingrouplen, linelen, TRUE);
> >
> > ------------------------------------------------------
> > http://subversion.tigris.org/ds/viewMessage.do?dsForumId=495&dsMessageId=1008146
> >
>

------------------------------------------------------
http://subversion.tigris.org/ds/viewMessage.do?dsForumId=462&dsMessageId=1013619
Received on 2009-01-09 12:55:56 CET

This is an archived mail posted to the Subversion Dev mailing list.