Solved

Splitting a pointer

Posted on 2000-02-27
4
228 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

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…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.

832 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