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 6626413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:53:23+00:00 2026-05-25T21:53:23+00:00

When I run the following function I get a SIGSEGV. I can’t figure out

  • 0

When I run the following function I get a SIGSEGV. I can’t figure out why…
Can anybody help? Point me in the right direction? I is ment as a part of a larger program which scans the directory hierarchy for duplicate files.

#include <stdio.h>
#include <stdlib.h>
#include <glib.h>

int main ( int argc , char *argv[]) {
    GError *error = NULL;
    const gchar* filename = NULL;
    gchar *directory_path = "/tmp";
    GDir* dp = g_dir_open (directory_path, 0, &error);
    if (error) {
        g_warning("g_dir_open() failed: %s\n", error->message);
        g_clear_error(&error);
        return 1;
        }
    while ( (filename = g_dir_read_name(dp)) ){
        filename = g_dir_read_name(dp);
        gchar* path = g_build_filename (directory_path, filename, NULL);
        printf("%s\n", filename);
        g_free (path);
    }
    return 0;
}
  • 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-25T21:53:23+00:00Added an answer on May 25, 2026 at 9:53 pm

    Maybe get rid of the second filename = g_dir_read_name(dp); (the first line inside of the loop)

    When it does the loop test condition, it already assigns filename to the next entry in the dir. If you run that line again from within the loop, it will attempt to read one more entry after the last one. If there are an odd number of files in the directory, filename could be pointing to a null value on the last execution of the loop.

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

Sidebar

Related Questions

Help me translate following block of the Haskell code. The run function produces text
I am trying to get the following function to run when the link is
I have the following function that I only want to run inside <div id=imgWrapper>
I have written the following function but it's isn't returning anything when I run
What is the check_union256d function? It's placed in following code: /* { dg-do run
Can not run following SQL from ant's sql task : BEGIN DBMS_AQADM.CREATE_QUEUE_TABLE( queue_table =>
I have the following function in Javascript: $find('mainWindow').repaint(); I need to run that inside
I'm getting a strange error when I run the following function: TypeIDs=c(18283,18284,17119,17121,17123,17125,17127,17129,17131,17133,18367,18369,18371,18373,18375,18377,18379) featsave<-function(featfile,TypeIDs=TypeIDs) {
i have following function: function fnGetIdentifiers(id){ $.get( 'getCultureIdentifiers.php?cultureID=' + id, function(data){ if (data.length >
I have a following script in PS: [System.Xml.XmlDocument] $Config; function Get-ScriptDirectory { Split-Path $script:MyInvocation.MyCommand.Path

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.