Subject: | bytes::length doesn't return the number of bytes/octets in a scalar |
Date: | Sun, 14 Mar 2010 00:28:47 +0100 |
To: | bug-anyevent-i3 [...] rt.cpan.org |
From: | Marc Lehmann <schmorp [...] schmorp.de> |
Hi!
I just had a quick look over AnyEvent::I3, and found a bug.
basically, your _bytelength doesn't do what you think it does - it ignores
the perl-internal encoding and returns the *internal* length in octets
(not the length of it's argument in octets).
this is wrong, as you later send the data over the wire (well,
ae::handle), and the other side cannot know how perl encoded the scalar,
so will get the wrong length.
if you want the length of $payload in octets (very likely), then you need
to use the normal length function, not bytes::length.
(you are lucky because currently, encode_json happens to return a scalar
where bytes::length and length agree - it can be wrong on user-supplied
messages however).
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / schmorp@schmorp.de
-=====/_/_//_/\_,_/ /_/\_\