Bug #27141 Calling tell(-1) under Windows causes assertion failure in Debug mode
Submitted: 14 Mar 2007 17:05 Modified: 18 Jun 2007 7:58
Reporter: Paul McCullagh (Basic Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.1.16 OS:Windows (Windows NT/XP)
Assigned to: Sergey Vojtovich CPU Architecture:Any
Tags: _lseeki64, assertion failure, tell, windows

[14 Mar 2007 17:05] Paul McCullagh
Description:
When testing under Windows with a Debug build, the following assertion fails:

Function: _lseeki64(), File: C:\Programme\Microsoft Visual Studio 8\VC\crt\src\lseeki64.c:

        _VALIDATE_CLEAR_OSSERR_RETURN((fh >= 0 && (unsigned)fh < (unsigned)_nhandle), EBADF, -1i64);

The assertion fails because the function is called with fh == -1

How to repeat:
Confirm the following call sequence:

 Function mv_cache.c: open_cached_file() calls:
 
  if (!init_io_cache(cache,-1,cache_size,WRITE_CACHE,0L,0,
		     MYF(cache_myflags | MY_NABP)))

Function mf_iocache.c: init_io_cache() calls:

	pos= my_tell(file, MYF(0));

Function my_seek: my_tell() calls:

  pos=tell(fd);

Under Windows tell() is defined as _telli64(). In file: C:\Programme\Microsoft Visual Studio 8\VC\crt\src\telli64.c, _telli64() calls:

        return( _lseeki64( filedes, 0i64, SEEK_CUR ) );

In _lseeki64() the assertion fails, as described above:

        _VALIDATE_CLEAR_OSSERR_RETURN((fh >= 0 && (unsigned)fh < (unsigned)_nhandle), EBADF, -1i64);

Suggested fix:
Although it is not critical (tell() will return EBADF), the error must be avoided to be able to test MySQL with a debug build under Windows. I suggest the following change to mf_iocache.c:

  if (file >= 0)
    pos= my_tell(file, MYF(0));
  else
    pos = 0;
[7 May 2007 23:02] MySQL Verification Team
Thank you for the bug report.
[2 Jun 2007 20:22] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/27998

ChangeSet@1.2504, 2007-06-03 05:14:57+05:00, svoj@mysql.com +1 -0
  BUG#27141 - Calling tell(-1) under Windows causes assertion failure in Debug mode
  
  Original problem was by Magnus (see BUG25807).
  
  Currently only windows debug build causes assertion failure. This patch assures
  that my_tell gets correct file descriptor on any platform by DBUG_ASSERT macro.
[4 Jun 2007 18:23] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/28073

ChangeSet@1.2504, 2007-06-05 03:16:02+05:00, svoj@mysql.com +1 -0
  BUG#27141 - Calling tell(-1) under Windows causes assertion failure in Debug mode
  
  Original problem was fixed by Magnus (see BUG25807).
  
  Currently only windows debug build causes assertion failure. This patch assures
  that my_tell gets correct file descriptor on any platform by DBUG_ASSERT macro.
[5 Jun 2007 7:42] Sergey Vojtovich
BUG#28590 was marked as duplicate.
[18 Jun 2007 7:48] Bugs System
Pushed into 5.1.20-beta
[18 Jun 2007 7:50] Bugs System
Pushed into 5.0.44
[18 Jun 2007 7:58] Sergey Vojtovich
No changelog entry needed for this bug.
[19 Jun 2007 10:26] Daniel Fischer
Didn't make it into 5.0.44, will be in 5.0.46.