Skip to content

bug: seek() to negative position doesn't set $! to EINVAL #342

@toddr-bot

Description

@toddr-bot

Problem

In Test::MockFile::FileHandle, when seek() attempts to seek to a negative position, it returns 0 (failure) but does NOT set $! to EINVAL.

# FileHandle.pm, SEEK method
if ( $new_pos < 0 ) {
    return 0;  # Missing: $! = EINVAL
}

Expected behavior

Real Perl's seek() sets $! to EINVAL when the resulting position would be negative.

Reproduction

use Test::MockFile;
use Errno qw(EINVAL);

my $file = Test::MockFile->file('/mock/test', 'hello');
open my $fh, '<', '/mock/test' or die;
my $result = seek($fh, -10, 0);  # Seek to negative position
# $result is 0 (correct), but $! is not EINVAL (bug)

Severity

🟢 Low — incorrect error reporting, but the operation itself correctly fails.


🤖 Created by Kōan from audit session

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions