Solved

Splitting a pointer

Posted on 2000-02-27
4
245 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

724 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