0

すべての引数は正しいですが、読み取られたアイテムの正しい値を返します。関数fread_sは、空の「バイト」で何も記述しません。10485760と1を交換すると、空になります。この問題の原因を誰かが知っていますか?ファイルに全く問題はありません。

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;
}

編集:解決済み

4

2 に答える 2

1
bytes = (char*)malloc(i);
// etc.
fread_s(&bytes, i, 1, i, handle->bestand); // Here and down below

のアドレスがバッファが存在する場所であるためではbytesなく、ここが必要です。&bytesbytes

于 2012-11-23T22:13:01.090 に答える
1

これが特定の問題であるかどうかはわかりませんがコードに問題があります。

呼び出しを行うときは、fread読み取りたい「オブジェクト」の数とオブジェクトサイズを指定してから、その数までfread読み取ります。ただし、それらのオブジェクトの正確な数を読み取ります。

したがって、7バイトのファイルから100万個の1バイトのオブジェクトを読み取ろうとすると、そのうちの7つが取得され、戻りコードにこれが反映されます。ただし、100万バイトのオブジェクトを読み取ろうとすると、何も取得されず、戻りコードにそれが反映されます。

戻り値を強調する理由は、必要な数よりも少ないオブジェクトを返す可能性があるため(たとえば、ファイルに900しか残っていない1000個の1バイトオブジェクトを要求した場合)、予想される量を出力ファイルに盲目的に書き込むためです。ノーノーです。リターンコードを確認し、それに基づいて行動する必要があります。

さらに、コメント投稿者が指摘しているように、出力ステートメントの1つで入力ファイルに書き戻しているように見えます。

fwrite (bytes, 1, 10485760, handle->bestand);

それがうまく終了する可能性は低いです:-)おそらく次のようになります:

fwrite (bytes, 1, 10485760, handle->nieuwbstnd);
于 2012-11-23T21:57:10.250 に答える