Skip Menu |

This queue is for tickets about the Encode CPAN distribution.

Report information
The Basics
Id: 124478
Status: resolved
Priority: 0/
Queue: Encode

People
Owner: Nobody in particular
Requestors: RANDIR [...] cpan.org
Cc: pali [...] cpan.org
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 2.98



Subject: VS2017 compilation warnings
hile building this module under 64-bit version of MS VS2017, I get the following build warnings: Encode.xs(491): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(692): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(752): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(863): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(898): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(929): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(1010): warning C4267: '=': conversion from 'size_t' to 'I32', possible loss of data Encode.xs(1077): warning C4244: '=': conversion from '__int64' to 'I32', possible loss of data Encode.xs(1081): warning C4267: '=': conversion from 'size_t' to 'I32', possible loss of data Encode.xs(1144): warning C4267: 'function': conversion from 'size_t' to 'U32', possible loss of data
Hi! On Pon Feb 19 18:07:15 2018, RANDIR wrote: Show quoted text
> hile building this module under 64-bit version of MS VS2017, I get the > following build warnings: > > Encode.xs(491): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data > Encode.xs(692): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data > Encode.xs(752): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data > Encode.xs(863): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data > Encode.xs(898): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data > Encode.xs(929): warning C4244: '=': conversion from 'IV' to 'int', > possible loss of data
See patch in the attachment, can you verify that it fixes these problems? Show quoted text
> Encode.xs(1010): warning C4267: '=': conversion from 'size_t' to > 'I32', possible loss of data > Encode.xs(1077): warning C4244: '=': conversion from '__int64' to > 'I32', possible loss of data > Encode.xs(1081): warning C4267: '=': conversion from 'size_t' to > 'I32', possible loss of data
Those warnings come from _bytes_to_utf8 and _utf8_to_bytes functions. I think that those functions should be rather removed as they are undocumented, marked as unimplemented, private (as they starts with underscore) and currently not used by Encode. Therefore I would not spend time for investigation of those warnings. Show quoted text
> Encode.xs(1144): warning C4267: 'function': conversion from 'size_t' > to 'U32', possible loss of data
Code looks to be OK, seems to be bug in compiler. So report it to the compiler bug tracker.
Subject: 0001-Set-correct-type-for-check-variable.patch
From b032849f6b55fa267d089f8930f695b43ad32c42 Mon Sep 17 00:00:00 2001 From: Pali <pali@cpan.org> Date: Mon, 5 Mar 2018 22:57:40 +0100 Subject: [PATCH] Set correct type for check variable Value assigned to check variable comes from SvIV() therefore it should be of IV type. Fixes following compile warnings on 64bit MS VS2017: Encode.xs(491): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(692): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(752): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(863): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(898): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data Encode.xs(929): warning C4244: '=': conversion from 'IV' to 'int', possible loss of data --- Encode.xs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Encode.xs b/Encode.xs index bc4a77d..68d1ccb 100644 --- a/Encode.xs +++ b/Encode.xs @@ -164,7 +164,7 @@ do_bytes_fallback_cb(pTHX_ U8 *s, STRLEN slen, SV *fallback_cb) static SV * encode_method(pTHX_ const encode_t * enc, const encpage_t * dir, SV * src, U8 * s, STRLEN slen, - int check, STRLEN * offset, SV * term, int * retcode, + IV check, STRLEN * offset, SV * term, int * retcode, SV *fallback_cb) { STRLEN tlen = slen; @@ -472,7 +472,7 @@ process_utf8(pTHX_ SV* dst, U8* s, U8* e, SV *check_sv, UV uv; STRLEN ulen; SV *fallback_cb; - int check; + IV check; U8 *d; STRLEN dlen; char esc[UTF8_MAXLEN * 6 + 1]; @@ -683,7 +683,7 @@ PREINIT: U8 *e; SV *dst; bool renewed = 0; - int check; + IV check; bool modify; dSP; INIT: @@ -744,7 +744,7 @@ PREINIT: U8 *s; U8 *e; SV *dst; - int check; + IV check; bool modify; INIT: SvGETMAGIC(src); @@ -848,7 +848,7 @@ SV * off SV * term SV * check_sv PREINIT: - int check; + IV check; SV *fallback_cb; bool modify; encode_t *enc; @@ -886,7 +886,7 @@ SV * obj SV * src SV * check_sv PREINIT: - int check; + IV check; SV *fallback_cb; bool modify; encode_t *enc; @@ -917,7 +917,7 @@ SV * obj SV * src SV * check_sv PREINIT: - int check; + IV check; SV *fallback_cb; bool modify; encode_t *enc; -- 2.11.0
On Mon Mar 05 17:05:27 2018, PALI wrote: Thanks, this patch silences all warnings you intended. Show quoted text
> > Encode.xs(1144): warning C4267: 'function': conversion from 'size_t' > > to 'U32', possible loss of data
> > Code looks to be OK, seems to be bug in compiler. So report it to the > compiler bug tracker.
Well, this is Visual Studio, you know. It seems to be really dumb and blindly checks strlen()'s return type without realizing it's called on a constant string and will never overflow. You can just cast it's result to U32, which gv_stashpvn expects.
On Pia mar 09 15:00:18 2018, RANDIR wrote: Show quoted text
>You can just cast it's result to U32, which gv_stashpvn expects.
Casting is already done there and you said that VS throws warning... Or do you mean to call (U32)strlen("Encode") ? Would not that again throw warning with possible data loss?
On Sat Mar 10 05:53:04 2018, PALI wrote: Show quoted text
> Or do you mean to call (U32)strlen("Encode") ? Would not that again > throw warning with possible data loss?
Yes, I mean (U32)strlen("Encode") - I've checked that it works.
Ok, pull request with patches is there: https://github.com/dankogai/p5-encode/pull/131
Fixed in Encode 2.98.
On Sat Jul 25 09:14:59 2020, PALI wrote: Show quoted text
> Fixed in Encode 2.98.