Skip to content

Instantly share code, notes, and snippets.

@mikezackles
Created June 8, 2015 19:24
Show Gist options
  • Save mikezackles/5fae14f3a0bed5fb13ac to your computer and use it in GitHub Desktop.
Save mikezackles/5fae14f3a0bed5fb13ac to your computer and use it in GitHub Desktop.
goto error_handling;
int read_file_normal(const char* filename)
{
FILE* f = fopen(filename, "rt");
char buf[100];
if (f == NULL) {
fprintf(stderr, "Failed to open %s", filename);
goto error_open;
}
if (fread(buf, sizeof(buf), 1, f) == 0) {
fprintf(stderr, "Failed to read data from %s\n", filename);
goto error_read;
}
if (fclose(f) == EOF) {
fprintf(stderr, "Failed to close %s\n", filename);
}
return 0;
error_read:
fclose(f);
error_open:
return -1;
}
@LBiv
Copy link

LBiv commented Jun 8, 2015

int foo(object *a) {

    object *temp, *res;

    if(!(temp = getb(a))) {
        return -1;
    }

    res = getc(temp);
    free(temp);

    if(!res) {
        return -1;
    }

    res = getd(temp = res);
    free(temp);

    if(!res) {
        return -1;
    }

}

@LBiv
Copy link

LBiv commented Jun 8, 2015

<interrupted else-if chain>
if(error) {
}
else if(exp) {
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment