09-29-2004
Will we get SEGV if we try to “delete []” un-initialized integer pointer variable.
I have a class with an integer pointer, which I have not initialized to NULL in the constructor. For example:
class myclass
{
private:
char * name;
int *site;
}
myclass:: myclass(....)
: name(NULL)
{
.....
}
other member function “delete [] “ the variable before initializing it.
Ex:
void myclass:: copy_site ( int **Values, int *from)
{
int *old;
old = *values.
Delete [] old; <<<<<ß here I am getting SEGV
...............
..............
}
But I am getting SEGV at “delete []”.
Surprisingly it is not happening every time. For only some inputs it is certainly working fine.
What could be the reason?
If it is because of initialization, why is working for some inputs and certainly not for other inputs?
I have observed with workshop that, for some inputs it is automatically getting initialized to NULL, and for other inputs it is certainly not NULL (dangling pointer).
Thanks in advance,
Suresh
10 More Discussions You Might Find Interesting
1. Programming
I received a warning when I tried to compile my program that said:
warning: comparison between pointer and integer
Could you please explain to me what this means, and in what ways I could possibly fix this?
Thanks for your help! (2 Replies)
Discussion started by: sjung10
2 Replies
2. Programming
can u tell me the reson that why we should not delete a pointer twice.?
if we delete ponter twice then what happen and why this happen
Regards,
Amit (2 Replies)
Discussion started by: amitpansuria
2 Replies
3. UNIX for Dummies Questions & Answers
Hello,
I am in following situation.-
COUNT=`ls -l | wc -l`
echo $COUNT
---> 26
NO_OF_FILES=$COUNT-1
echo $NO_OF_FILES
---> 26-1
Here, I want the output to be 25. How could I do this. It seems simple, but I am not getting it. Please help me. (2 Replies)
Discussion started by: The Observer
2 Replies
4. Programming
A question to ask.
seq1 = "eeeeeeeeeeeeeeeeee";
seq2 = "dddddddddddddddddddd";
char a = '*';
strcat(*seq2, &a);
strcat(*seq1, seq2);
compilation
warning: passing arg 1 of `strcat' makes pointer from integer without a cast
thanks (4 Replies)
Discussion started by: cdbug
4 Replies
5. Programming
If one wants to get a start address of a array or a string or a block of memory via a function, there are at least two methods to achieve it:
(1) one is to pass a pointer-to-pointer parameter, like:
int my_malloc(int size, char **pmem)
{
*pmem=(char *)malloc(size);
if(*pmem==NULL)... (11 Replies)
Discussion started by: aaronwong
11 Replies
6. Programming
I use solaris10,following is tcp client code:
#include "cliserv.h"
int main(int argc,char argv){
struct sockaddr_in serv;
char request,reply;
int sockfd,n;
if(argc!=2)
err_quit("usage: tcpclient <IP address of server>");
if((sockfd=socket(PF_INET,SOCK_STREAM,0))<0)
... (1 Reply)
Discussion started by: konvalo
1 Replies
7. Shell Programming and Scripting
I would like to know the maximum integer that a variable can hold. Actually one of my variable holds value 2231599773 and hence the script fails to process it.Do we have any other data type or options available to handle this long integers? (9 Replies)
Discussion started by: michaelrozar17
9 Replies
8. Solaris
hello,
i am writing a script that takes the UID from the PASSWD and then i want
to increse the Number by one. for the Next user.
i cannot get this to work that a variable is as interger
example:
set i = 0
set $i = $+1
it's in tcsh if it's mather (10 Replies)
Discussion started by: shatztal
10 Replies
9. Programming
Hi guys :D
I am still playing with my C handbook and yes, as you can see I have small problem as always :cool:
I wrote a C code
#include <stdio.h> #define MESSAGE 100 int main(void) { char input_mes - Pastebin.com
And when I try to compile it I get following errors from gcc
... (1 Reply)
Discussion started by: solaris_user
1 Replies
10. UNIX for Dummies Questions & Answers
I'm trying to write a programme which scans strings to find how many vowels they contain. I get an error saying that I'm trying to compare a pointer and an integer inif(*v == scanme){. How can I overcome this ? Also, the programme seems to scan only the first word of a string e.g.: if I type "abc... (1 Reply)
Discussion started by: fakuse
1 Replies
LEARN ABOUT FREEBSD
g_geom
G_GEOM(9) BSD Kernel Developer's Manual G_GEOM(9)
NAME
g_new_geomf, g_destroy_geom -- geom management
SYNOPSIS
#include <geom/geom.h>
struct g_geom *
g_new_geomf(struct g_class *mp, const char *fmt, ...);
void
g_destroy_geom(struct g_geom *gp);
DESCRIPTION
The geom (do not confuse ``geom'' with ``GEOM'') is an instance of a GEOM class. For example: in a typical i386 FreeBSD system, there will
be one geom of class MBR for each disk. The geom's name is not really important, it is only used in the XML dump and for debugging purposes.
There can be many geoms with the same name.
The g_new_geomf() function creates a new geom, which will be an instance of the class mp. The geom's name is created in a printf(3)-like way
from the rest of the arguments.
The g_destroy_geom() function destroys the given geom immediately and cancels all related pending events.
The g_geom structure contains fields that should be set by the caller after geom creation, but before creating any providers or consumers
related to this geom (not all are required):
g_start_t * start
Pointer to a function used for I/O processing.
g_spoiled_t * spoiled
Pointer to a function used for consumers spoiling.
g_dumpconf_t * dumpconf
Pointer to a function used for configuration in XML format dumping.
g_access_t * access
Pointer to a function used for access control.
g_orphan_t * orphan
Pointer to a function used to inform about orphaned consumer.
g_ioctl_t * ioctl
Pointer to a function used for handling ioctl requests.
void * softc
Field for private use.
RESTRICTIONS
/CONDITIONS
If you intend to use providers in this geom you must set field start of your geom.
If you are planning to use consumers in your geom you must set fields orphan and access for it.
g_new_geomf():
Class mp must be valid (registered in GEOM).
The topology lock has to be held.
g_destroy_geom():
The geom cannot possess any providers.
The geom cannot possess any consumers.
The topology lock has to be held.
RETURN VALUES
The g_new_geomf() function returns a pointer to the newly created geom.
EXAMPLES
Create an example geom.
static struct geom *
g_example_start(struct bio *bp)
{
[...]
}
static void
g_example_orphan(struct g_consumer *cp)
{
g_topology_assert();
[...]
}
static void
g_example_spoiled(struct g_consumer *cp)
{
g_topology_assert();
[...]
}
static void
g_example_access(struct g_provider *pp, int dr, int dw, int de)
{
[...]
}
static struct g_geom *
create_example_geom(struct g_class *myclass)
{
struct g_geom *gp;
g_topology_lock();
gp = g_new_geomf(myclass, "example_geom");
g_topology_unlock();
gp->start = g_example_start;
gp->orphan = g_example_orphan;
gp->spoiled = g_example_spoiled;
gp->access = g_example_access;
gp->softc = NULL;
return (gp);
}
static int
destroy_example_geom(struct g_geom *gp)
{
g_topology_lock();
if (!LIST_EMPTY(&gp->provider) ||
!LIST_EMPTY(&gp->consumer)) {
g_topology_unlock();
return (EBUSY);
}
g_destroy_geom(gp);
g_topology_unlock();
return (0);
}
SEE ALSO
geom(4), DECLARE_GEOM_CLASS(9), g_access(9), g_attach(9), g_bio(9), g_consumer(9), g_data(9), g_event(9), g_provider(9),
g_provider_by_name(9), g_wither_geom(9)
AUTHORS
This manual page was written by Pawel Jakub Dawidek <pjd@FreeBSD.org>.
BSD
January 16, 2004 BSD