projects
/
AXE.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
String constructor and assignment from char * are more robust fro NULL pointers.
[AXE.git]
/
src
/
string.cpp
diff --git
a/src/string.cpp
b/src/string.cpp
index
1bcded9
..
c1cb1b8
100644
(file)
--- a/
src/string.cpp
+++ b/
src/string.cpp
@@
-5,7
+5,7
@@
***********************
** FILE NAME : string.cpp
** SYSTEM NAME : Andromeda X-Windows Encapsulation
***********************
** FILE NAME : string.cpp
** SYSTEM NAME : Andromeda X-Windows Encapsulation
-** VERSION NUMBER : $Revision: 1.
3
$
+** VERSION NUMBER : $Revision: 1.
4
$
**
** DESCRIPTION : String class implementation.
**
**
** DESCRIPTION : String class implementation.
**
@@
-23,7
+23,10
@@
/*****************************
$Log: string.cpp,v $
/*****************************
$Log: string.cpp,v $
- Revision 1.3 2002-11-03 13:18:57 arjen
+ Revision 1.4 2003-03-29 07:18:54 arjen
+ String constructor and assignment from char * are more robust fro NULL pointers.
+
+ Revision 1.3 2002/11/03 13:18:57 arjen
New functions - String::escape() and String::unescape()
Revision 1.2 2002/09/28 06:42:11 arjen
New functions - String::escape() and String::unescape()
Revision 1.2 2002/09/28 06:42:11 arjen
@@
-34,7
+37,7
@@
*****************************/
*****************************/
-static const char RCSID[] = "$Id: string.cpp,v 1.
3 2002-11-03 13:18:57
arjen Exp $";
+static const char RCSID[] = "$Id: string.cpp,v 1.
4 2003-03-29 07:18:54
arjen Exp $";
#include <stdio.h>
#include <ctype.h>
#include <stdio.h>
#include <ctype.h>
@@
-61,9
+64,16
@@
String::String(char c) // Create a String from a char
String::String(const char *s) // Create a String from a char *
{
p = new srep;
String::String(const char *s) // Create a String from a char *
{
p = new srep;
- p->s = new char[strlen(s)+1];
-
strcpy(p->s, s)
;
+
+
p->s = 0
;
p->n = 1;
p->n = 1;
+
+ if (s != 0)
+ {
+ p->s = new char[strlen(s)+1];
+ strcpy(p->s, s);
+ p->n = 1;
+ }
}
String::String(const String& x) // Create a String from another String
}
String::String(const String& x) // Create a String from another String
@@
-122,9
+132,12
@@
String& String::operator=(const char *s)
else if (p->n == 1)
delete p->s;
else if (p->n == 1)
delete p->s;
- p->s = new char[strlen(s)+1];
- strcpy(p->s, s);
- p->n = 1;
+ if (s != 0)
+ {
+ p->s = new char[strlen(s)+1];
+ strcpy(p->s, s);
+ p->n = 1;
+ }
return *this;
}
return *this;
}