Skip to content

Fix error_code() reporting errors in Data::BitStream instead of caller#1

Open
Stevie-O wants to merge 3 commits intodanaj:masterfrom
Stevie-O:master
Open

Fix error_code() reporting errors in Data::BitStream instead of caller#1
Stevie-O wants to merge 3 commits intodanaj:masterfrom
Stevie-O:master

Conversation

@Stevie-O
Copy link
Copy Markdown

error_code() uses 'confess' to raise errors from the perspective of the
caller. However, that caller is always a component of Data::BitStream, so
the result looks like this:

invalid parameters: bits must be <= 64 at C:/Perl64/site/lib/Data/BitStream/WordVec.pm line 107.

By including 'ref $self' in @CARP_NOT, the error message points to the correct
location:

invalid parameters: bits must be <= 64 at myscript.pl line 125.

error_code() uses 'confess' to raise errors from the perspective of the
caller.  However, that caller is always a component of Data::BitStream, so
the result looks like this:

invalid parameters: bits must be <= 64 at C:/Perl64/site/lib/Data/BitStream/WordVec.pm line 107.

By including 'ref $self' in @CARP_NOT, the error message points to the correct
location:

invalid parameters: bits must be <= 64 at myscript.pl line 125.
WordVec::to_raw returns the raw internal buffer directly, which may not be
correct in all cases, due to optimizations elsewhere.

The two cases in particular are as follows:

* write(N, 0) does not actually store N '0' bits in the buffer; instead, it
simply increments the internal length indicator.  As such, if the last write
to the stream wrote a zero value, to_raw() may be shorter than it ought to be.

* Other write operations increase the size by multiples of 32 bits.  Therefore,
the return value could be up to 3 bytes longer than it should have been.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant