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

  • Home
  • SEARCH
  • 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 8089065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:17:18+00:00 2026-06-05T19:17:18+00:00

I have been creating a gtk+ application in eclipse. At a point in the

  • 0

I have been creating a gtk+ application in eclipse. At a point in the code, an alert dialogue is displayed using code similar to the gtk+ hello world. When I run this program, the dialogue ends up displaying the content of ‘words’ as expected, but the program crashes when I close the dialogue. I am new to c, so I ran the program with debug expecting to find some simple mistake. However, when i ran with debug, the dialogue displayed ‘words’ preceded by many null characters and logged the message.

Pango-WARNING **: Invalid UTF-8 string passed to pango_layout_set_text()

This new problem is confusing, and to add to the confusion, the program also did not crash when the dialogue was closed.

In summary, when I run the code, the text is fine, and the program crashes. When I debug the code, the text is invalid, and the program does not crash.

The text in the dialogue is generated with the following code:

char*  answerBuffer = (char*)malloc(strlen(s)+strlen(words)+1);

strcat(answerBuffer,words);

char*  answer = (char*)malloc(strlen(answerBuffer)+1);
g_strlcpy(answer,answerBuffer,strlen(answerBuffer)+1);

return answer;

as the code executes, the length of answerBuffer is 320 and words is a char* argument set to “a,b,c,d”. I am running this on windows xp through eclipse with the minGW compiler using gtk+ 2.24. Can anyone tell me how to debug/fix this?

ps. ‘s’ contains text from a file followed by either one or twelve null characters (one if I run, twelve if I debug)

  • 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-06-05T19:17:20+00:00Added an answer on June 5, 2026 at 7:17 pm

    Given the code you’ve supplied, this line is the problem:

    strcat(answerBuffer,words);
    

    Why? Because you don’t know what is in answerBuffer. Malloc doesn’t necessarily zero memory it returns to you, so answerBuffer contains essentially random bytes. You need to zero at least the first byte (so it looks like a zero length string), or use calloc() to allocate your buffer, which gives you zeroed memory.

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

Sidebar

Related Questions

I have been successful in creating a tooltip for text using code similar to:
I have been reading that creating dependencies by using static classes/singletons in code, is
Hello Guys! See I have been creating a code powered with ajax but it
I have been creating a web scraper for an internal application with PHP but
I have been creating user login form using the various groupcodes, the user login
I have been creating my application in a primarily programatic approach and have been
I have been creating an ASP.net web application for my client. This will be
I have been working on creating an application that sends a string from an
I have been working on creating an RPG combat sim for code-practice. A single
I have been creating and using a page on the development environment for awhile,

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.