Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6876189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:26:47+00:00 2026-05-27T04:26:47+00:00

This is driving me crazy, so any help will be appreciated. I am developing

  • 0

This is driving me crazy, so any help will be appreciated.

I am developing a program that scans for Wi-fi access points and manages them with different functionalities. One of those is to save the access points list to a file, another is to read access points from a file and add them to the current list.
Access points are stored in a linked list where ‘p’ contains the info of one access point (mac, mode, encrypted, essid, etc..), and ‘next’ is the pointer to the next node.

Here is part of the function i use to save:

void store_info_in_file(list l)
{
 list aux;
 aux = l;
 FILE *file;
 ..
 ..
 //After opening the file with a name chosen by the user,it traverses 
 //the list and with casts to char, saves each part of each access point.

 //Conversion to char to ease storage in a binary file.

 char essid_len = (char)strlen((aux->p).essid);
 char enc = (char)(aux->p).encrypted; //originally an int

 fwrite(&essid_len,1,1,file);//i'm guessing the size is sizeof(char) now

And the same for all the parts.
Analyzing the file output with a hex editor, i can see that the data has been stored correctly.

This is the problematic part of the read function:(i read the first character [number of access points contained in the file] and store it for later conversion to int).

 //new_apns is for later use, when i will fread the rest of the file at once.
 char new_apns;
 ////wifi_collector_list.c:1103
 fread(&new_apns,1,1,fp);

This causes a segmentation fault due to an invalid read of size 4.
Here is the output for:

“valgrind –leak-check=full –show-reachable=yes –track-origins=yes ./app”

http://pastebin.com/LAwsCV11

Edit:
I am definitely stupid, I had written:

 fp = fopen(string,"rb");
 if(fp != NULL)
 {
  //fread here
 }

And for some reason changed it to:

 if(fopen(string,"rb"))
 {
  //fread here, so yes, it's null...
 }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T04:26:48+00:00Added an answer on May 27, 2026 at 4:26 am
    ==21328== Invalid read of size 4
    ==21328==    at 0x40D8F35: fread (iofread.c:43)
    ==21328==    by 0x804F043: add_info_from_file (wifi_collector_list.c:1103)
    ...
    Address 0x0 is not stack'd, malloc'd or (recently) free'd
            ^^^
    

    That’s a huge hint that fp is NULL at the time of the fread. Maybe you didn’t check it when you fopened it ?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy , so any help would be awesome: My html
Ok, this is driving me crazy. I have a CA that needs to know
This is driving me crazy. I'm not including any code because I want to
This is driving me crazy. Very grateful if someone could help me out! Problem:
This is driving me crazy. Just testing a site on IE9 and discovered that
I'm driving myself crazy trying to understand Expressions in LINQ. Any help is much
This is driving me crazy. I have this one php file on a test
This is driving me crazy. I'm not going to take it anymore. I'm going
This is driving me crazy and has resulted in lost work (not much, at
This is driving me crazy, so... When resizing image to small thumbnail, resulting image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.