儘管所有參數都是正確的,但它返回讀取項目的正確值,函數fread_s不會講述「bytes」中的任何內容爲空。當我交換時,它也是空的10485760 & 1.有誰知道是什麼原因導致了這個問題?根本沒有問題。爲什麼fread_s不能在這個C代碼中工作?
float EncryptBig(CRYPTIN* handle)
{
int i, index = 0;
float calc;
char* bytes;
i = (handle->size - handle->huidig);
if ((i-10485760) < 0)
{
bytes = (char*)malloc(i);
if (bytes == NULL)
{
fcloseall();
free(handle);
return 100.0f;
}
fread_s(&bytes, i, 1, i, handle->bestand); // Here and down below
fclose(handle->bestand);
for (index = 0; index < i; index++)
{
__asm
{
mov eax, dword ptr [bytes]
add eax, dword ptr [index]
mov cl, byte ptr [eax]
xor cl, 101
xor cl, 53
not cl
mov byte ptr [eax], cl
mov eax, dword ptr [index]
add eax, 1
mov dword ptr [index], eax
}
}
fwrite(bytes, 1, i, handle->nieuwbstnd);
fclose(handle->nieuwbstnd);
free(handle);
free(bytes);
return 100.0f;
}
if (handle->huidig == 0)
{
fseek(handle->bestand, 0, SEEK_SET);
fseek(handle->nieuwbstnd, 0, SEEK_SET);
}
bytes = (char*)malloc(10485760);
if (bytes == NULL)
{
fcloseall();
free(handle);
return 100.0f;
}
fread_s(bytes, 10485760, 10485760, 1, handle->bestand); // Here
for (index = 0; index < 10485760; index++)
{
__asm
{
mov eax, dword ptr [bytes]
add eax, dword ptr [index]
mov cl, byte ptr [eax]
xor cl, 101
xor cl, 53
not cl
mov byte ptr [eax], cl
mov eax, dword ptr [index]
add eax, 1
mov dword ptr [index], eax
}
}
fwrite(bytes, 1, 10485760, handle->bestand);
free(bytes);
handle->huidig += 10485760;
handle->positie += 10485760;
fseek(handle->bestand, handle->huidig, SEEK_SET);
fseek(handle->nieuwbstnd, handle->positie, SEEK_SET);
calc = (float)handle->huidig;
calc /= (float)handle->size;
calc *= 100.0f;
if (calc >= 100.0)
{
fclose(handle->bestand);
fclose(handle->nieuwbstnd);
free(handle);
}
return calc;
}
編輯:解決
'fwrite(bytes,1,10485760,handle-> bestand);'< - 你不想寫'handle-> nieuwbstnd'嗎? –
如果你不檢查'fread_s()'的返回值,你怎麼知道有什麼問題?此外,通過指定錯誤報告功能,您可以控制錯誤報告(至少在「* _s()」函數的TR24731或C 2011版本中)。 –
寫if'((i-10485760)<0)'而不是更簡單,更清晰的if(i <10485760)'有什麼好處? Fortran II曾經需要類似於這種迂迴的東西,但Fortran IV(又名Fortran 66)終止了這種需求。 –