-3
if (srcbloc == NULL) {
    fprintf(stderr, "warning!: memrip source is null!\n");
    exit(1);
}
if (destbloc == NULL) {
    destbloc = malloc(len);
}
if (srcbloc == destbloc) {
    fprintf(stderr, "warning!: srcbloc = destbloc\n");
    exit(1);
}
if (offset < 0) {
    fprintf(stderr, "warning!: offset = %i\n", offset);
}
if (len < 0) {
    fprintf(stderr, "warning!: len = %i\n", len);
}

I am wondering if all of the if statements will be tested when this program is run?

MD XF
  • 7,860
  • 7
  • 40
  • 71
skrillac
  • 11
  • 1
  • 3

1 Answers1

1

Given your code

if (srcbloc == NULL) { /* <-- if this block is entered then, */
  fprintf(stderr, "warning!: memrip source is null!\n"); 
  exit(1); /* <-- Program will exit */ 
}
if (destbloc == NULL) {  /* <-- Allocate destbloc of len length. */
  destbloc = malloc(len); 
}
if (srcbloc == destbloc) { /* <-- if this block is entered then, */
  fprintf(stderr, "warning!: srcbloc = destbloc\n"); 
  exit(1); /* <-- Program will exit */ 
}
if (offset < 0) { 
  fprintf(stderr, "warning!: offset = %i\n", offset); 
}
if (len < 0) { 
  fprintf(stderr, "warning!: len = %i\n", len); 
}

So, if (srcbloc == NULL) or (srcbloc == destbloc) the program will warn (and exit). If any of the other tests match the warnings will be printed but the program will continue to process.

Elliott Frisch
  • 198,278
  • 20
  • 158
  • 249