Skip to content

Instantly share code, notes, and snippets.

@wirewc
Last active August 29, 2015 14:12

Revisions

  1. wirewc revised this gist Jan 1, 2015. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions stringFunctionSet.c
    Original file line number Diff line number Diff line change
    @@ -14,8 +14,8 @@ void copy_string(char *target, char *source)

    void implant(char *stuff)
    {
    char* loader = "Hello";
    copy_string(stuff, loader);
    char loader[] = "Hello";
    copy_string(stuff, (char*)loader);
    }


    @@ -27,12 +27,12 @@ int main(void)
    implant(toload);

    printf("%s\n",toload);

    free(toload);

    implant(toload);

    printf("%s\n",toload);
    implant(toload);
    printf("%s\n",toload);

    return 0;
    }
    }
  2. wirewc created this gist Jan 1, 2015.
    38 changes: 38 additions & 0 deletions stringFunctionSet.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    #include <stdlib.h>
    #include <stdio.h>
    #include <string.h>

    void copy_string(char *target, char *source)
    {
    while(*source)
    {
    *target = *source;
    source++; target++;
    }
    *target = '\0';
    }

    void implant(char *stuff)
    {
    char* loader = "Hello";
    copy_string(stuff, loader);
    }



    int main(void)
    {
    char *toload = malloc(20);

    implant(toload);

    printf("%s\n",toload);

    free(toload);

    implant(toload);

    printf("%s\n",toload);

    return 0;
    }