You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@apr.apache.org by Jean-frederic Clere <jf...@gmail.com> on 2006/03/30 14:47:30 UTC
apr-iconv (error: invalid lvalue in increment)
Hi,
I am trying to compile trunk and I have a problem in apr-iconv the
corrections are like the patch below.
The memcpy is a bit paranoid, any comments?
Cheers
Jean-frederic
+++
jfclere@vtxclere:~/apr-iconv$ svn diff .
Index: ces/ucs2-internal.c
===================================================================
--- ces/ucs2-internal.c (revision 390028)
+++ ces/ucs2-internal.c (working copy)
@@ -59,7 +59,9 @@
return -1; /* No corresponding character in UCS-2 */
if (*outbytesleft < sizeof(ucs2_t))
return 0; /* No space in the output buffer */
- *((ucs2_t *)(*outbuf))++ = in;
+ /* memcpy prevents addressing problems */
+ *outbuf += sizeof(ucs2_t);
+ memcpy(*outbuf, &in, sizeof(ucs2_t));
(*outbytesleft) -= sizeof(ucs2_t);
return 1;
}
@@ -68,10 +70,14 @@
convert_to_ucs(struct iconv_ces *ces,
const unsigned char **inbuf, apr_size_t *inbytesleft)
{
+ ucs2_t ret;
if (*inbytesleft < sizeof(ucs2_t))
return UCS_CHAR_NONE; /* Not enough bytes in the input
buffer */
(*inbytesleft) -= sizeof(ucs2_t);
- return *((const ucs2_t *)(*inbuf))++;
+ /* memcpy prevents addressing problems */
+ *inbuf += sizeof(ucs2_t);
+ memcpy(&ret, *inbuf, sizeof(ucs2_t));
+ return ret;
}
static const struct iconv_ces_desc iconv_ces_desc = {
+++
Re: apr-iconv (error: invalid lvalue in increment)
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
The memcpy suggestion is definately suboptimal, lots of overhead, etc.
The solution's pretty trivial, once you have an lhs pointer of the correct
type the bug goes away. This can involve correcting the lhs type throughout
the function (sometimes), or in more complex cases, having a second pointer
variable.
See http://svn.apache.org/viewcvs.cgi?rev=386790&view=rev
for how this was solved in mod_isapi.c
Jean-frederic Clere wrote:
> William A. Rowe, Jr. wrote:
>
>> This is very similar to the recent patches on
>> httpd/trunk/modules/arch/win32
>> in the mod_isapi module. Now trying to build on gcc4 and Sunstudio 11
>> cc, I'n
>> finding more and more issues with LHS cast expressions not resolving
>> as a valid
>> lhs target of the assignment operator.
>>
>> It's silly, but needs to be patched :-/
>
>
> Ok, with memcpy or with ** and casts?
>
> Cheers
>
> Jean-Frederic
>
>>
>> Jean-frederic Clere wrote:
>>
>>> Hi,
>>>
>>> I am trying to compile trunk and I have a problem in apr-iconv the
>>> corrections are like the patch below.
>>> The memcpy is a bit paranoid, any comments?
>>>
>>> Cheers
>>>
>>> Jean-frederic
>>>
>>> +++
>>> jfclere@vtxclere:~/apr-iconv$ svn diff .
>>> Index: ces/ucs2-internal.c
>>> ===================================================================
>>> --- ces/ucs2-internal.c (revision 390028)
>>> +++ ces/ucs2-internal.c (working copy)
>>> @@ -59,7 +59,9 @@
>>> return -1; /* No corresponding character in UCS-2 */
>>> if (*outbytesleft < sizeof(ucs2_t))
>>> return 0; /* No space in the output buffer */
>>> - *((ucs2_t *)(*outbuf))++ = in;
>>> + /* memcpy prevents addressing problems */
>>> + *outbuf += sizeof(ucs2_t);
>>> + memcpy(*outbuf, &in, sizeof(ucs2_t));
>>> (*outbytesleft) -= sizeof(ucs2_t);
>>> return 1;
>>> }
>>> @@ -68,10 +70,14 @@
>>> convert_to_ucs(struct iconv_ces *ces,
>>> const unsigned char **inbuf, apr_size_t *inbytesleft)
>>> {
>>> + ucs2_t ret;
>>> if (*inbytesleft < sizeof(ucs2_t))
>>> return UCS_CHAR_NONE; /* Not enough bytes in the
>>> input buffer */
>>> (*inbytesleft) -= sizeof(ucs2_t);
>>> - return *((const ucs2_t *)(*inbuf))++;
>>> + /* memcpy prevents addressing problems */
>>> + *inbuf += sizeof(ucs2_t);
>>> + memcpy(&ret, *inbuf, sizeof(ucs2_t));
>>> + return ret;
>>> }
>>>
>>> static const struct iconv_ces_desc iconv_ces_desc = {
>>> +++
>>>
>>>
>>
>>
>
>
>
Re: apr-iconv (error: invalid lvalue in increment)
Posted by Jean-frederic Clere <jf...@gmail.com>.
William A. Rowe, Jr. wrote:
> This is very similar to the recent patches on
> httpd/trunk/modules/arch/win32
> in the mod_isapi module. Now trying to build on gcc4 and Sunstudio 11
> cc, I'n
> finding more and more issues with LHS cast expressions not resolving
> as a valid
> lhs target of the assignment operator.
>
> It's silly, but needs to be patched :-/
Ok, with memcpy or with ** and casts?
Cheers
Jean-Frederic
>
> Jean-frederic Clere wrote:
>
>> Hi,
>>
>> I am trying to compile trunk and I have a problem in apr-iconv the
>> corrections are like the patch below.
>> The memcpy is a bit paranoid, any comments?
>>
>> Cheers
>>
>> Jean-frederic
>>
>> +++
>> jfclere@vtxclere:~/apr-iconv$ svn diff .
>> Index: ces/ucs2-internal.c
>> ===================================================================
>> --- ces/ucs2-internal.c (revision 390028)
>> +++ ces/ucs2-internal.c (working copy)
>> @@ -59,7 +59,9 @@
>> return -1; /* No corresponding character in UCS-2 */
>> if (*outbytesleft < sizeof(ucs2_t))
>> return 0; /* No space in the output buffer */
>> - *((ucs2_t *)(*outbuf))++ = in;
>> + /* memcpy prevents addressing problems */
>> + *outbuf += sizeof(ucs2_t);
>> + memcpy(*outbuf, &in, sizeof(ucs2_t));
>> (*outbytesleft) -= sizeof(ucs2_t);
>> return 1;
>> }
>> @@ -68,10 +70,14 @@
>> convert_to_ucs(struct iconv_ces *ces,
>> const unsigned char **inbuf, apr_size_t *inbytesleft)
>> {
>> + ucs2_t ret;
>> if (*inbytesleft < sizeof(ucs2_t))
>> return UCS_CHAR_NONE; /* Not enough bytes in the
>> input buffer */
>> (*inbytesleft) -= sizeof(ucs2_t);
>> - return *((const ucs2_t *)(*inbuf))++;
>> + /* memcpy prevents addressing problems */
>> + *inbuf += sizeof(ucs2_t);
>> + memcpy(&ret, *inbuf, sizeof(ucs2_t));
>> + return ret;
>> }
>>
>> static const struct iconv_ces_desc iconv_ces_desc = {
>> +++
>>
>>
>
>
Re: apr-iconv (error: invalid lvalue in increment)
Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
This is very similar to the recent patches on httpd/trunk/modules/arch/win32
in the mod_isapi module. Now trying to build on gcc4 and Sunstudio 11 cc, I'n
finding more and more issues with LHS cast expressions not resolving as a valid
lhs target of the assignment operator.
It's silly, but needs to be patched :-/
Jean-frederic Clere wrote:
> Hi,
>
> I am trying to compile trunk and I have a problem in apr-iconv the
> corrections are like the patch below.
> The memcpy is a bit paranoid, any comments?
>
> Cheers
>
> Jean-frederic
>
> +++
> jfclere@vtxclere:~/apr-iconv$ svn diff .
> Index: ces/ucs2-internal.c
> ===================================================================
> --- ces/ucs2-internal.c (revision 390028)
> +++ ces/ucs2-internal.c (working copy)
> @@ -59,7 +59,9 @@
> return -1; /* No corresponding character in UCS-2 */
> if (*outbytesleft < sizeof(ucs2_t))
> return 0; /* No space in the output buffer */
> - *((ucs2_t *)(*outbuf))++ = in;
> + /* memcpy prevents addressing problems */
> + *outbuf += sizeof(ucs2_t);
> + memcpy(*outbuf, &in, sizeof(ucs2_t));
> (*outbytesleft) -= sizeof(ucs2_t);
> return 1;
> }
> @@ -68,10 +70,14 @@
> convert_to_ucs(struct iconv_ces *ces,
> const unsigned char **inbuf, apr_size_t *inbytesleft)
> {
> + ucs2_t ret;
> if (*inbytesleft < sizeof(ucs2_t))
> return UCS_CHAR_NONE; /* Not enough bytes in the input
> buffer */
> (*inbytesleft) -= sizeof(ucs2_t);
> - return *((const ucs2_t *)(*inbuf))++;
> + /* memcpy prevents addressing problems */
> + *inbuf += sizeof(ucs2_t);
> + memcpy(&ret, *inbuf, sizeof(ucs2_t));
> + return ret;
> }
>
> static const struct iconv_ces_desc iconv_ces_desc = {
> +++
>
>