_mktemp_s - валиться
От: Alca Украина  
Дата: 27.08.11 18:03
Оценка:
#include "stdafx.h"
#include <io.h>
#include <string.h>
#include <stdio.h>
#include <iostream>

char *fnTemplate = "fnXXXXXX";
char names[5][9];

int _tmain(int argc, _TCHAR* argv[])
{
   int i, err, sizeInChars;
   FILE *fp;

   for( i = 0; i < 500000000; i++ )
   {
      strcpy_s( names[i], sizeof(names[i]), fnTemplate );
      /* Get the size of the string and add one for the null terminator.*/
      sizeInChars = strnlen(names[i], 9) + 1;
      /* Attempt to find a unique filename: */
      errno = 0;
      err = _mktemp_s( names[i], sizeInChars );
      if( err != 0 )
         printf( "Problem creating the template: %s\n", strerror(errno));
      else
      {
         if( fopen_s( &fp, names[i], "w" ) == 0 )
            printf( "Unique filename is %s\n", names[i] );
         else
            printf( "Cannot open %s\n", names[i] );
         fclose( fp );
      }

      remove(names[i]);

      std::cout << ">>>>>>>>>>>>>>>>>>>>> " <<  i << std::endl;
   }

   return 0;
}


Вывод:
start _mktemp_s
end _mktemp_s
Unique filename is fna02276
>>>>>>>>>>>>>>>>>>>>> 0
start _mktemp_s
end _mktemp_s
Unique filename is fna02276
>>>>>>>>>>>>>>>>>>>>> 1
start _mktemp_s
end _mktemp_s
Unique filename is fna02276
>>>>>>>>>>>>>>>>>>>>> 2
start _mktemp_s
end _mktemp_s
Unique filename is fna02276

...

>>>>>>>>>>>>>>>>>>>>> 505
start _mktemp_s
end _mktemp_s
Unique filename is fna02276
>>>>>>>>>>>>>>>>>>>>> 506
start _mktemp_s
end _mktemp_s
Unique filename is fna02276
>>>>>>>>>>>>>>>>>>>>> 507
start _mktemp_s


Валево:
---------------------------
TempFile.exe - Ошибка приложения
---------------------------
Инструкция по адресу "0x58585858" обратилась к памяти по адресу "0x58585858". Память не может быть "read".


"ОК" -- завершение приложения
"Отмена" -- отладка приложения
---------------------------
ОК   Отмена   
---------------------------


Почему валиться прога?
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.