Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8872929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:20:20+00:00 2026-06-14T18:20:20+00:00

I’m having trouble with this code. When I execute PrepareEncryption (in example), the code

  • 0

I’m having trouble with this code. When I execute “PrepareEncryption” (in example), the code returns a valid pointer, but when I pass it on to “EncryptBig” it isn’t valid no more (points to random numbers). My best bet is that the original struct is deleted. So how do I preserve it, if that’s the problem? And I know that there is a memory leak btw.

struct filecrypt
{
    FILE* bestand;
    FILE* nieuwbstnd;
    unsigned int positie;
    unsigned int size;
    unsigned int huidig;
    float procentum;
};

struct filecrypt *PrepareEncryption(char* locatie)
{
    struct stat file_status;
    struct filecrypt origineel, *mirror;
    int error;
    char* nieuw;

    if (stat(locatie, &file_status) != 0)
        return NULL;

    error = fopen_s(&origineel.bestand, locatie, "rb");
    if (error != 0)
        return NULL;

    error = strlen(locatie)+5;
    nieuw = (char*)malloc(error);
    if (nieuw == NULL)
        return NULL;
    strcpy_s(nieuw, error-3, locatie);
    strcat_s(nieuw, error, ".cpt");

    error = fopen_s(&origineel.nieuwbstnd, nieuw, "wb+");
    if (error != 0)
        return NULL;

    origineel.huidig = 0;
    origineel.positie = 0;
    origineel.procentum = 0.0f;
    origineel.size = file_status.st_size;
    mirror = &origineel;
    return mirror;
}

float EncryptBig(struct filecrypt *handle)
{
    int i, index = 0;
    float calc;
    char buf, *bytes = (char*)malloc(10485760); // 10 MB
    if (bytes == NULL)
    {
        handle = NULL;
        fcloseall();
        return -1.0f;
    }

    for (i = handle->huidig; i < (handle->huidig+10485760); i++)
    {
        if (i > handle->size)
            break;

        fseek(handle->bestand, i, SEEK_SET);
        fread_s(&buf, 1, 1, 1, handle->bestand);

        __asm
        {
            mov         eax, dword ptr [bytes]  
            add         eax, dword ptr [index]  
            mov         cl, byte ptr [buf]
            xor         cl, 18
            xor         cl, 75
            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);
    fseek(handle->nieuwbstnd, i, SEEK_SET);

    handle->huidig += i;
    calc = (float)handle->huidig;
    calc /= (float)handle->size;
    calc *= 100.0f;

    if (calc == 100.0)
    {
        // GEHEUGEN LEK!
        // MOET NOG BIJGEWERKT WORDEN!
        fcloseall();
        handle = NULL;
    }
    return calc;
}

void example(char* path)
{
    float progress;
    struct filecrypt* handle;

    handle = PrepareEncryption(path);
    do
    {
        progress = EncryptBig(handle);
        printf_s("%f", progress);
    }
    while (handle != NULL);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T18:20:21+00:00Added an answer on June 14, 2026 at 6:20 pm

    It’s because you return a pointer to a local variable.

    Local variables are stored on the stack, and when a function returns that area of the stack is reused by other functions, and you are left with a pointer that now points to unused memory or memory now occupied by something else. This is undefined behaviour, and might sometimes work, might sometimes give you “garbage” data, and may sometimes crash.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
This could be a duplicate question, but I have no idea what search terms
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.