Solved

Splitting a pointer

Posted on 2000-02-27
4
206 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Ahh,  I had a tuser, and a ttuser,  I used the wrong one to init.  Thanks.. :P
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Dll Dynamic way c/c++ 9 133
logging Access violation 6 18
scanf and assignment suppression 13 143
Why this code doesn't work? 8 93
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…
Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

744 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

18 Experts available now in Live!

Get 1:1 Help Now