Skip to content

Commit

Permalink
avoid compiler/linker warnings
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@32483 72102866-910b-0410-8b05-ffd578937521
  • Loading branch information
rfm committed Mar 7, 2011
1 parent 695c2d2 commit 96e4898
Show file tree
Hide file tree
Showing 23 changed files with 273 additions and 169 deletions.
26 changes: 26 additions & 0 deletions ChangeLog
@@ -1,3 +1,29 @@
2011-03-06 Richard Frith-Macdonald <rfm@gnu.org>

* Source/NSPortCoder.m:
* Source/NSKeyValueCoding.m:
* Source/NSPathUtilities.m:
* Source/NSProcessInfo.m:
* Source/NSMethodSignature.m:
* Source/NSMessagePort.m:
* Source/NSInvocation.m:
* Source/dld-load.h:
* Source/NSFileManager.m:
* Source/NSURL.m:
* Source/NSString.m:
* Source/Additions/Unicode.m:
* Source/Additions/NSError+GNUstepBase.m:
* Source/Additions/GSXML.m:
* Source/Additions/GSObjCRuntime.m:
* Source/NSData.m:
* Source/NSHost.m:
* Source/GSMDNSNetServices.m:
* Source/GSValue.m:
* Source/NSTask.m:
* Tools/defaults.m:
* Tools/locale_alias.m:
Avoid strcpy and strcat to get rid if some bsd warnings.

2011-03-06 Richard Frith-Macdonald <rfm@gnu.org>

* config/config.initialize.m: Correct formatting. Increase time
Expand Down
7 changes: 5 additions & 2 deletions Source/Additions/GSObjCRuntime.m
Expand Up @@ -427,6 +427,7 @@ Class GSObjCSuper(Class cls)
Class classSuperClass;
const char *classNameCString;
char *tmp;
int len;

NSCAssert(name, @"no name");
NSCAssert(superName, @"no superName");
Expand All @@ -437,8 +438,10 @@ Class GSObjCSuper(Class cls)
NSCAssert1(!NSClassFromString(name), @"A class %@ already exists", name);

classNameCString = [name UTF8String];
tmp = malloc(strlen(classNameCString) + 1);
strcpy(tmp, classNameCString);
len = strlen(classNameCString);
tmp = malloc(len + 1);
strncpy(tmp, classNameCString, len);
tmp[len] = '\0';
classNameCString = tmp;

newClass = objc_allocateClassPair(classSuperClass, classNameCString, 0);
Expand Down
2 changes: 1 addition & 1 deletion Source/Additions/GSXML.m
Expand Up @@ -150,7 +150,7 @@ + (IMP) methodForSelector: (SEL)aSelector;
{
unsigned len = (from == 0) ? 1 : (strlen(from) + 1);
char *to = malloc(len);
strcpy(to, from);
memcpy(to, from, len);
return to;
}

Expand Down
10 changes: 6 additions & 4 deletions Source/Additions/NSError+GNUstepBase.m
Expand Up @@ -60,14 +60,15 @@ @implementation NSError(GNUstepBase)
ptr = strerror(eno);
if (ptr == 0)
{
strncpy(buf, "unknown error number", len);
strncpy(buf, "unknown error number", len - 1);
result = -1;
}
else
{
strncpy(buf, strerror(eno), len);
strncpy(buf, strerror(eno), len - 1);
result = 0;
}
buf[len - 1] = '\0';
[gnustep_global_lock unlock];
return result;
}
Expand All @@ -80,10 +81,11 @@ @implementation NSError(GNUstepBase)

if (eno < 0 || eno >= sys_nerr)
{
strncpy(buf, "unknown error number", len);
strncpy(buf, "unknown error number", len - 1);
return -1;
}
strncpy(buf, sys_errlist[eno], len);
strncpy(buf, sys_errlist[eno], len - 1);
buf[len - 1] = '\0';
return 0;
}
#endif
Expand Down
11 changes: 6 additions & 5 deletions Source/Additions/Unicode.m
Expand Up @@ -324,15 +324,16 @@ static void GSSetupEncodingTable(void)
if (entry->iconv != 0 && *(entry->iconv) != 0)
{
iconv_t c;
int l;
char *lossy;

/*
* See if we can do a lossy conversion.
*/
lossy = NSZoneMalloc(NSDefaultMallocZone(),
strlen(entry->iconv) + 12);
strcpy(lossy, entry->iconv);
strcat(lossy, "//TRANSLIT");
l = strlen(entry->iconv);
lossy = NSZoneMalloc(NSDefaultMallocZone(), l + 11);
strncpy(lossy, entry->iconv, l);
strncpy(lossy + l, "//TRANSLIT", 11);
c = iconv_open(UNICODE_ENC, entry->iconv);
if (c == (iconv_t)-1)
{
Expand Down Expand Up @@ -2565,8 +2566,8 @@ static inline int chop(unichar c, _ucc_ *table, int hi)
/* Take it from the system locale information. */
[gnustep_global_lock lock];
strncpy(encbuf, nl_langinfo(CODESET), sizeof(encbuf)-1);
[gnustep_global_lock unlock];
encbuf[sizeof(encbuf)-1] = '\0';
[gnustep_global_lock unlock];
encoding = encbuf;

/*
Expand Down
2 changes: 0 additions & 2 deletions Source/GSMDNSNetServices.m
Expand Up @@ -1523,8 +1523,6 @@ + (NSData *) dataFromTXTRecordDictionary: (NSDictionary *) txtDictionary
break;
}

strcat(key, "\0");

if ([[values objectAtIndex: i] isKindOfClass: [NSString class]])
{
char value[256];
Expand Down
6 changes: 4 additions & 2 deletions Source/GSValue.m
Expand Up @@ -100,8 +100,10 @@ - (id) initWithBytes: (const void *)value
data = (void *)NSZoneMalloc([self zone], size);
memcpy(data, value, size);
}
objctype = (char *)NSZoneMalloc([self zone], strlen(type)+1);
strcpy(objctype, type);
size = strlen(type);
objctype = (char *)NSZoneMalloc([self zone], size + 1);
strncpy(objctype, type, size);
objctype[size] = '\0';
}
return self;
}
Expand Down
19 changes: 12 additions & 7 deletions Source/NSData.m
Expand Up @@ -1327,7 +1327,8 @@ - (BOOL) writeToFile: (NSString *)path

if (local_c_path != 0 && strlen(local_c_path) < (BUFSIZ*2))
{
strcpy(theRealPath,local_c_path);
strncpy(theRealPath, local_c_path, sizeof(theRealPath) - 1);
theRealPath[sizeof(theRealPath) - 1] = '\0';
error_BadPath = NO;
}
}
Expand All @@ -1344,8 +1345,9 @@ - (BOOL) writeToFile: (NSString *)path
int desc;
int mask;

strcpy(thePath, theRealPath);
strcat(thePath, "XXXXXX");
strncpy(thePath, theRealPath, sizeof(thePath) - 1);
thePath[sizeof(thePath) - 1] = '\0';
strncat(thePath, "XXXXXX", 6);
if ((desc = mkstemp(thePath)) < 0)
{
NSWarnMLog(@"mkstemp (%s) failed - %@", thePath, [NSError _last]);
Expand All @@ -1361,7 +1363,8 @@ - (BOOL) writeToFile: (NSString *)path
}
else
{
strcpy(thePath, theRealPath);
strncpy(thePath, theRealPath, sizeof(thePath) - 1);
thePath[sizeof(thePath) - 1] = '\0';
theFile = fopen(thePath, "wb");
}
#else
Expand All @@ -1381,8 +1384,9 @@ - (BOOL) writeToFile: (NSString *)path
goto failure;
}
#else
strcpy(thePath, theRealPath);
strcat(thePath, "XXXXXX");
strncpy(thePath, theRealPath, sizeof(thePath) - 1);
thePath[sizeof(thePath) - 1] = '\0';
strncat(thePath, "XXXXXX", 6);
if (mktemp(thePath) == 0)
{
NSWarnMLog(@"mktemp (%s) failed - %@", thePath, [NSError _last]);
Expand All @@ -1395,7 +1399,8 @@ - (BOOL) writeToFile: (NSString *)path
#if defined(__MINGW__)
wcscpy(wthePath,wtheRealPath);
#else
strcpy(thePath, theRealPath);
strncpy(thePath, theRealPath, sizeof(thePath) - 1);
thePath[sizeof(thePath) - 1] = '\0';
#endif
}

Expand Down
2 changes: 1 addition & 1 deletion Source/NSFileManager.m
Expand Up @@ -813,7 +813,7 @@ - (BOOL) createDirectoryAtPath: (NSString*)path
return NO;
}

strcpy(dirpath, lpath);
strncpy(dirpath, lpath, len);
dirpath[len] = '\0';
if (dirpath[len-1] == '/')
dirpath[len-1] = '\0';
Expand Down
3 changes: 2 additions & 1 deletion Source/NSHost.m
Expand Up @@ -280,7 +280,8 @@ @implementation NSHost
}
else if (name == nil || strcmp(old, buf) != 0)
{
strcpy(old, buf);
strncpy(old, buf, sizeof(old) - 1);
old[sizeof(old) - 1] = '\0';
RELEASE(name);
name = [[NSString alloc] initWithCString: buf];
}
Expand Down
14 changes: 10 additions & 4 deletions Source/NSInvocation.m
Expand Up @@ -481,10 +481,13 @@ - (void) setArgument: (void*)buffer
}
else
{
int len;
char *tmp;

tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(newstr)+1);
strcpy(tmp, newstr);
len = strlen(newstr);
tmp = NSZoneMalloc(NSDefaultMallocZone(), len + 1);
strncpy(tmp, newstr, len);
tmp[len] = '\0';
_set_arg(self, index, tmp);
}
if (oldstr != 0)
Expand Down Expand Up @@ -615,9 +618,12 @@ - (void) retainArgumentsIncludingTarget: (BOOL)retainTargetFlag
if (str != 0)
{
char *tmp;
int len;

tmp = NSZoneMalloc(NSDefaultMallocZone(), strlen(str)+1);
strcpy(tmp, str);
len = strlen(str);
tmp = NSZoneMalloc(NSDefaultMallocZone(), len + 1);
strncpy(tmp, str, len);
tmp[len] = '\0';
_set_arg(self, i-1, &tmp);
}
}
Expand Down

0 comments on commit 96e4898

Please sign in to comment.