LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-03-2004, 11:23 AM   #1
jpbarto
Senior Member
 
Registered: Mar 2003
Location: Pittsburgh, PA
Distribution: Gentoo / NetBSD
Posts: 1,251

Rep: Reputation: 45
slightly different question (about XSync)


I've been wrestling with this question for about two days now and some have tried to help me but the problem has overcome all suggestions. Can someone please explain to me why this occurs:

I have a struct:
typedef struct {
/* string to display */
char *str;
/* string length, of course */
int slen;
/* position (in percentage) to place string */
/* where top-left-most of window is 0.0,0.0 and */
/* bottom-right-most of window is 1.0,1.0 */
float pos_x;
float pos_y;
} txt_element;

typedef struct {
Pixmap *img;
float pos_x;
float pos_y;
} img_element;

typedef struct {
txt_element t_element;
img_element i_element;
/* command to populate element */
char *cmd;
/* if no command, then a custom function to populate the element */
void (*func) (void *);
/* double var to store a reading (to be displayed by a guage) */
double data_value;
/* will the string change over the course of the apps lifetime */
BOOL constant;
} scr_element;


so then I have a function that populates the 'str' element of txt_element. with the following code:
if ((s_element->t_element.str = malloc(24)) != NULL){
sprintf(s_element->t_element.str, "CPU 0\n %3.2f%%", s_element->data_value);
}

When I sprintf this text:
CPU 0\nLoad: %3.2f%%

it crashes, but with the Load: removed (with a text string small enough) the app stays running. Also, it doesn't crash (when the text is too big) at the sprintf but at a call to XSync that occurs later.

What is the relationship between my struct in memory and XSync that causes this thing to segfault? (ps gdb outputs an error at 'chunk_alloc').

Thanks for any help,
jpbarto
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Need a slightly modified bootdisk.... jsalbre Slackware - Installation 3 12-20-2004 08:04 AM
slightly off topic DNS question benbroad Linux - Networking 8 12-01-2004 09:49 AM
(Slightly OT) Do I Need Bluetooth? jxbrown Linux - Wireless Networking 2 05-07-2004 12:42 PM
(slightly ot)agp 2x not 4x??? Motown Linux - Hardware 0 03-20-2004 09:40 AM
Slightly off topic, but... Stephanie General 11 01-14-2002 09:34 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration