bind - (fscanf(file, "%lf", &num) > 0) and segmentation fault in C -


i'm modifying piece of source code of bind, random order section of rdataset.c file, below:

for (i = 0; < count; i++) {     dns_rdata_t rdata;     isc_uint32_t val;      isc_random_get(&val);     choice = + (val % (count - i));     rdata = shuffled[i];     shuffled[i] = shuffled[choice];     shuffled[choice] = rdata;     if (order != null)         sorted[i].key = (*order)(&shuffled[i], order_arg);     else         sorted[i].key = 0; /* unused */     sorted[i].rdata = &shuffled[i]; } 

i change line choice , let variable taken function

choice=weightcal(); 

and code of function

unsigned int weightcal() {     file *file = fopen("weight.txt", "r");       double integers[10],prob[10];      unsigned int i=0,j=0,k=0;      double sum=0,subsum=0,num;      unsigned int result=0;     while(fscanf(file, "%lf", &num) > 0) {         integers[i] =num;         sum+=num;         i++;         }     rewind(file);         while(fscanf(file, "%lf", &num) > 0){         subsum=subsum+num;           prob[j]= subsum / sum;           j++;     }        srand(time(null));        double r = rand() / (double)rand_max;         for(k=0;k<sizeof(prob)/sizeof(double);k++) {         if (r <  prob[k]) {                  result=k;                    break;           }         }      fclose(file);     return result; } 

then recompile bind. compilation works when use command :

dig www.example.com. @127.0.0.1  

it returns error "segmentation fault (core dumped)." tried debug , debugger told me error in line

while(fscanf(file, "%lf", &num) > 0) 

how can fix error?

check return value of line:

file *file = fopen("weight.txt", "r");  

i'd with:

file *file = fopen("weight.txt", "r");  if (file == null)  {     printf("unable open file weight.txt!  theres problem\n"); } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -