You need to check the return value of your calls; the second fscanf does
not match anything and therefore doesn't assign anything.
//Number 5
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
int main (int argc, char *argv[]) {
int8_t *numarray = NULL;
FILE *numfile = NULL;
int ret;
numarray = calloc(10, sizeof(int8_t));
if (! numarray)
perror("calloc");
numfile = fopen("fscanfbug.c", "r");
if (! numfile)
perror("fopen");
if (fscanf(numfile, "//Number %"PRId8, &numarray[8]) != 1)
printf("First fscanf returned wrong number of elements\n");
if (fscanf(numfile, "//Number %"PRId8, &numarray[7]) != 1)
printf("Second fscanf returned wrong number of elements\n");
printf("The 8th number is: %"PRId8"\n", numarray[8]);
printf("The 7th number is: %"PRId8" (shouldn't this be the same as above?)
\n", numarray[7]);
fclose(numfile);
free(numarray);
return 1;
}
if you run this, you will see that it complains at the second fscanf.
** Changed in: glibc (Ubuntu)
Status: Unconfirmed => Rejected
--
fscanf out of bounds write
https://bugs.launchpad.net/bugs/110917
You received this bug notification because you are a member of Ubuntu
Bugs, which is the bug contact for Ubuntu.
--
ubuntu-bugs mailing list
[email protected]
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs