It has some long background in front of the actual question, however, it carries some explanations, to hopefully weed some red herrings.
Our application, developed in Microsoft Visual C ++ (2005), uses a third-party library (with the source code, which we, fortunately, we have), to export the compressed file used in another third-party application. The library is responsible for creating the exported file, managing data and compressing and, as a rule, handling all errors. Recently, we began to receive feedback that on some machines our application will crash while writing to a file. Based on some initial research, we were able to determine the following:
- Accidents occurred on various hardware settings and operating systems (although our clients are limited to XP / 2000)
- Accidents always happen on one data set; however, they will not be found in all data sets.
- For a set of data that caused a crash, the accident cannot be reproduced on all machines even with the same characteristics, that is, with the operating system, the amount of RAM, etc.
- The error will appear only when the application was launched in the installation directory - not when creating from Visual Studio, starting in debug mode, or even starting in other directories that the user had access to
- The problem occurs if the file is created on a local or mapped drive.
, ( ):
while (size>0) {
do {
nbytes = _write(file->fd, buf, size);
} while (-1==nbytes && EINTR==errno);
if (-1==nbytes)
throw("file write failed")
assert(nbytes>0);
assert((size_t)nbytes<=size);
size -= (size_t)nbytes;
addr += (haddr_t)nbytes;
buf = (const char*)buf + nbytes;
}
, _write 22 EINVAL. MSDN, _write return EINVAL , (buf ) . , , , .
- 250 , . , , , , . , , , / . , :
- - , _write ? - _write - - Visual ++?
- - , ( 250 , ) - - , , , ?
UPDATE:
, :
- , . , , ( )
- , . , EINVAL , 0, buf , , .
:
printfs .
while (size>0) {
if (NULL == buf)
{
printf("Buffer is null\n");
}
do {
nbytes = _write(file->fd, buf, size);
} while (-1==nbytes && EINTR==errno);
if (-1==nbytes)
{
if (NULL == buf)
{
printf("Buffer is null post write\n");
}
printf("Error number: %d\n", errno);
printf("Buffer address: %d\n", &buf);
printf("Size: %d\n", size);
throw("file write failed")
}
assert(nbytes>0);
assert((size_t)nbytes<=size);
size -= (size_t)nbytes;
addr += (haddr_t)nbytes;
buf = (const char*)buf + nbytes;
}
:
Error number: 22
Buffer address: 1194824
Size: 89702400
, ( NULL , pre post _write)
, . (, , ) .
1. . , RAID (RAID 0 RAID 1) . RAID 0 ; RAID 1 . , ; - / - .
2. . , _write, 64 , . 32 , . , _write , , .
, ( Microsoft , ) , EINVAL . , , - - API- C.
- , , . , .