Solved

Splitting a pointer

Posted on 2000-02-27
4
217 Views
Last Modified: 2010-04-15
What am I doing wrong here?  I am trying to split this pointer into two vars,

Can anyone help?


char *tdom, *tuser;
if ((tdom = strchr(p->pop_parm[1], 47)))
{
*tdom = '\0';
memcpy(tuser, p->pop_parm[1], sizeof(p->pop_parm[1]));
tdom++;
}
tuser[strlen(tuser) - strlen(tdom) - 1] = '\0';
(void)strncpy(p->domain, tdom, sizeof(p->domain) - 1);
p->domain[sizeof(p->domain)-1] = '\0';
(void)strncpy(p->user, tuser, sizeof(p->user));
p->user[sizeof(p->user)-1] = '\0';
pop_msg(p, POP_SUCCESS, "User: %s %d %d, Domain: %s %d %d",  p->user, sizeof(p->pop_parm[1]), sizeof(p->user), p->domain, sizeof(tdom), sizeof(p->domain));

0
Comment
Question by:Nitro187
  • 2
  • 2
4 Comments
 
LVL 2

Accepted Solution

by:
AndrewRodionov earned 75 total points
ID: 2563819
Hello Nitro187!

I think your problem consists in using pointer that is NOT initialized. Look,
you declare tuser and it points to... nothing! It looks like an auto variable therefore it contains garbage until you assign a reasonable value. So you'll get an access violation in

memcpy(tuser, p->pop_parm[1], sizeof(p->pop_parm[1]));

Besides, tdom = strchr(p->pop_parm[1], 47) can return NULL and your assignment *tdom = '\0'; can fail too...

There are some incomprehensibilities and I need more information about p pointer.

Andrew


0
 

Author Comment

by:Nitro187
ID: 2566881
Hey,  ok, here is the struct, which P comes from:

typedef struct  {
int                 debug;
int                 xmitting;
int                 stats;
int                 dirty;
int                 kerberos;
int                 server_mode;
char            *   myname;
char            *   myhost;
char            *   client;
char            *   ipaddr;
unsigned short      ipport;
char                user[MAXUSERNAMELEN];
char                domain[MAXDOMAINLEN];
state               CurrentState;
int                 msgs_deleted;
int                 last_msg;
long                bytes_deleted;
char                drop_name[MAXDROPLEN];
char                temp_drop[MAXDROPLEN]
long                drop_size;
long                spool_end;
FILE            *   drop;              
FILE            *   input;
FILE            *   output;
FILE            *   trace;
FILE            *   hold;
char            *   pop_parm[MAXPARMCOUNT];
int                 parm_count;
char            *   bulldir;
} POP;

Any more ideas?
0
 
LVL 2

Expert Comment

by:AndrewRodionov
ID: 2567608
Other code (from (void)strncpy(p->domain,... ) looks like correct. Once more, your problem is in tuser pointer.

What does it point to? I think it's NOT initialized!..

Andrew
0
 

Author Comment

by:Nitro187
ID: 2571297
Ahh,  I had a tuser, and a ttuser,  I used the wrong one to init.  Thanks.. :P
0

Featured Post

Make managing Office 365 email signatures a breeze

Are you using Office 365? Having trouble trying to set up email signatures for your users? Getting stressed out managing multiple signatures? Need an easier way to manage? We have a solution for you, try the most-user friendly and powerful signature management tool on the market.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why debugging a macro i s difficult 10 28
Read file descriptor 3 in C 14 104
Parsing XML instructions in Java/any other language.... 3 104
Computer slow / BSOD 10 38
Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now