Mi dite che c'è di sbagliato in questo codice????
Devo leggere da un file blocchi di 64 byte e metterli
in un array di stringhe.
Quando dopo nel for verifico se sono stati
letti correttamente va in Segmentation fault.
void cryptText(char *filename,mpz_t *cryptedText,mpz_t e,mpz_t n) {
int in,nBlocchi=0,i,j,nRead;
char *buffer=NULL;
char **blocchi=NULL;
mpz_t temp,pText;
mpz_init(temp);
mpz_init(pText);
if ((in = open(filename, O_RDONLY))<0) {
printf("Errore: Impossibile aprire il file %s per la lettura\n", filename);
exit(1);
}
char *buffer=NULL;
char **blocchi=NULL;
buffer=(char *)malloc(DIMBLOCCO);
blocchi=(char **)malloc(sizeof(char *));
while((nRead=read(in, buffer, DIMBLOCCO))==DIMBLOCCO) {
blocchi[nBlocchi]=(char *)malloc(nRead);
strncpy(blocchi[nBlocchi],buffer,nRead);
nBlocchi++;
}
// blocchi[nBlocchi]=(char *)malloc(nRead*sizeof(char));
// strncpy(blocchi[nBlocchi],buffer,nRead);
//cryptedText=(mpz_t*)malloc(nBlocchi*sizeof(mpz_t)) ;
for(i=0;i<nBlocchi;i++) {
//mpz_set(pText,zero);
printf("%s\n",blocchi[i]);
//mpz_set_ui(temp,(int)blocchi[i][j]);
//mpz_mul_2exp(pText,pText,8);
//mpz_ior(pText,pText,temp);
//
//mpz_powm(cryptedText[i],pText,e,n);
}
close(in);
}