崩潰,我使用的Visual Studio 2013來構建交流應用的fopen和fopen_s似乎對長文件名
的代碼看起來是這樣的 -
int main(int argc, char *argv[])
{
char *InFilename = NULL;
char *OutFilename = NULL;
int ff_count; // counts the number of successive 0xff's read from the file buffer
int fpga_end, nios_start, nios_end; // used to report the size of each region
int file_length, file_index, temp_length, new_file_length;
int root_length;
int result;
FILE *infile = NULL;
FILE *outfile = NULL;
printf("Start JIC 2 rbf\r\n");
if ((argc != 2))
{
printf("\r\n\r\nV1.2 - Usage: <jic2rbf> <name of jicfile> \r\n");
printf("\r\n This program strips out the header info at the top of the file\r\n");
printf("\r\n and most of the ff's at the bottom. \r\n");
exit(1);
}
//
// Extract the name of the input file up to the '.' and use it to create the output file name with a .rbf extension.
//
InFilename = argv[1];
root_length = strcspn(InFilename,".");
printf("Root len = %d\r\n",root_length);
OutFilename = (char *)malloc(root_length+EXT_LENGTH);
memcpy(OutFilename,InFilename,root_length);
OutFilename[root_length] = 0;
strcat(OutFilename,".rbf");
printf("In file to be used %s\r\n", InFilename);
printf("Out file to be used %s\r\n", OutFilename);
result = fopen_s(&outfile, OutFilename, "wb");
if (result)
{
printf("Cannot open this file %s\r\n - 0x%x", OutFilename, result);
return 0;
}
printf("Open In - %d\r\n",result);
如果我把從DOS命令這個可執行文件
E:/projects/Q4300_Hdcp/q_series_hdcp_base/fpga/q_series_hdcp_tx_dual_singleHID/par/q_series_hdcp_tx_dual_singleHID/output_files/q_series_hdcp_tx_dual_singleHID_elf.jic
整個應用程序的工作
如果我所說的申請 - 與線使用以下命令行 -
E:/projects/Q4300_Hdcp/q_series_hdcp_base/fpga/q_series_hdcp_tx_dual_fpga/par/q_series_hdcp_tx_dual_fpga/output_files/q_series_hdcp_tx_dual_fpga_elf.jic
我沒有看到printf("Open In - %d\r\n",result);
輸出。該應用程序似乎崩潰。 我認爲這可能是某種緩衝區溢出的文件名稱,但較短的文件名工程.....如果我cd
到目錄與文件和調用命令行q_series_hdcp_tx_dual_fpga_elf.jic
的工作。 如果我DIR文件 - E:/projects/Q4300_Hdcp/q_series_hdcp_base/fpga/q_series_hdcp_tx_dual_fpga/par/q_series_hdcp_tx_dual_fpga/output_files/q_series_hdcp_tx_dual_fpga_elf.jic
我看到文件.......
我不知道如何捕捉到異常或什麼別的追求解決這個問題,任何想法將是巨大的。 謝謝, 馬丁
爲什麼用'memcpy'複製字符串?你不能使用'strcpy'嗎?另外,你的malloc需要爲空終止符分配一個額外的字符。 – bruceg
「EXT_LENGTH」未被聲明/定義在任何地方。它的價值很重要。 – chux
@bruceg OP不是試圖複製_string_,而是一個部分,因此合理使用'memcpy()'。 – chux