このコードでは複数の問題が考えられますが、コンパイラのエラーを解決したい最初。ご提案いただきありがとうございます。次にランエラーを解決しようとします。
エラー:エラーの種類:fuzzer.c:26:25:警告:代入なしのポインタからの整数の代入[-Wint-conversion]
fuzzer.c: In function ‘main’:
fuzzer.c:26:25: warning: assignment makes integer from pointer without a cast [-Wint-conversion]
charArray[arraySize-1] = NULL; /*make sure charArray[] is a string array that has a size of arraySize */
^
コード:すべての
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/wait.h>
#include <time.h>
int main(void)
{
int fuzzNum = 100;
char buffer[1000], *charArray;
int status, ret, i, j, retCode, arraySize; /* */
time_t t;
FILE *fin;
FILE *fout;
srand((unsigned) time(&t)); /* randomize the initial seed */
for(i=0; i<fuzzNum; i++)
{
charArray = (char *) malloc(arraySize);
for (j=0; j< arraySize; j++)
charArray[j] = 'A';
charArray[arraySize-1] = NULL;
/*make sure charArray[] is a string array that has a size of arraySize */
/* open and read the cross.jpg file as a binary format file*/
fin=fopen("./cross.jpg","rb");
/*generate a variable file name*/
char fileName[30]; int n;
sprintf(fileName, "crashed-%d.jpg", n);
fout=fopen("./test.jpg","wb");
/* execute the jpg2bmp file to process the test.jpg file*/
char comBuf[200];
sprintf(comBuf, "./jpg2bmp test.jpg temp.bmp");
ret=system(comBuf);
free(charArray); /* must free memory for repeat testing! */
ret=system(buffer);
wait(&status);
retCode=WEXITSTATUS(ret);
if (retCode == 128+11 || retCode ==128+6) /* segmentation fault (11) or Abort (6) */
{
printf("retCode=%d, arraySize = %d", retCode, arraySize);
fflush(stdout); /*make sure output is print out immediately ! */
}
}
return 0;
}
'charArray [arraySize-1] = NULL;' - > 'charArray [arraySize-1] = 0;'。また、 'arraySize'は初期化されていません。 – BLUEPIXY
まず、これは警告であり、エラーではありません。次に、なぜ 'charArray [arraySize-1] = 0;'? –
charArrayは配列arraySizeではありません。charArrayは文字列配列ではないためです。これはchar配列(したがって名前)です。 – immibis