Fix fl_vsnprintf bugs, remove VC++.NET link warnings

git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@4507 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
Michael R Sweet 2005-08-11 14:12:23 +00:00
parent b5a0c5bcc9
commit 497b30ae71
7 changed files with 49 additions and 53 deletions

View File

@ -42,10 +42,10 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
sign, /* Sign of format width */
size, /* Size character (h, l, L) */
type; /* Format type character */
const char *bufformat; /* Start of format */
int width, /* Width of field */
prec; /* Number of characters of precision */
char tformat[100], /* Temporary format string for sprintf() */
*tptr, /* Pointer into temporary format */
temp[1024]; /* Buffer for formatted numbers */
char *s; /* Pointer to string */
int slen; /* Length of string */
@ -62,45 +62,69 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
while (*format) {
if (*format == '%') {
bufformat = format;
format ++;
tptr = tformat;
*tptr++ = *format++;
if (*format == '%') {
*bufptr++ = *format++;
if (bufptr && bufptr < bufend) *bufptr++ = *format;
bytes ++;
format ++;
continue;
} else if (strchr(" -+#\'", *format)) sign = *format++;
else sign = 0;
} else if (strchr(" -+#\'", *format)) {
*tptr++ = *format;
sign = *format++;
} else sign = 0;
if (*format == '*') {
// Get width from argument...
format ++;
width = va_arg(ap, int);
snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", width);
tptr += strlen(tptr);
} else {
width = 0;
while (isdigit(*format & 255)) width = width * 10 + *format++ - '0';
while (isdigit(*format & 255)) {
if (tptr < (tformat + sizeof(tformat) - 1)) *tptr++ = *format;
width = width * 10 + *format++ - '0';
}
}
if (*format == '.') {
if (tptr < (tformat + sizeof(tformat) - 1)) *tptr++ = *format;
format ++;
if (*format == '*') {
// Get precision from argument...
format ++;
prec = va_arg(ap, int);
snprintf(tptr, sizeof(tformat) - (tptr - tformat), "%d", prec);
tptr += strlen(tptr);
} else {
prec = 0;
while (isdigit(*format & 255)) prec = prec * 10 + *format++ - '0';
while (isdigit(*format & 255)) {
if (tptr < (tformat + sizeof(tformat) - 1)) *tptr++ = *format;
prec = prec * 10 + *format++ - '0';
}
}
} else prec = -1;
if (*format == 'l' && format[1] == 'l') {
size = 'L';
if (tptr < (tformat + sizeof(tformat) - 2)) {
*tptr++ = 'l';
*tptr++ = 'l';
}
format += 2;
} else if (*format == 'h' || *format == 'l' || *format == 'L') size = *format++;
} else if (*format == 'h' || *format == 'l' || *format == 'L') {
if (tptr < (tformat + sizeof(tformat) - 1)) *tptr++ = *format;
size = *format++;
}
if (!*format) break;
type = *format++;
if (tptr < (tformat + sizeof(tformat) - 1)) *tptr++ = *format;
type = *format++;
*tptr = '\0';
switch (type) {
case 'E' : /* Floating point formats */
@ -108,11 +132,7 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
case 'e' :
case 'f' :
case 'g' :
if ((format - bufformat + 1) > sizeof(tformat) ||
(width + 2) > sizeof(temp)) break;
strncpy(tformat, bufformat, (size_t)(format - bufformat));
tformat[format - bufformat] = '\0';
if ((width + 2) > sizeof(temp)) break;
sprintf(temp, tformat, va_arg(ap, double));
@ -138,11 +158,7 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
case 'o' :
case 'u' :
case 'x' :
if ((format - bufformat + 1) > sizeof(tformat) ||
(width + 2) > sizeof(temp)) break;
strncpy(tformat, bufformat, (size_t)(format - bufformat));
tformat[format - bufformat] = '\0';
if ((width + 2) > sizeof(temp)) break;
sprintf(temp, tformat, va_arg(ap, int));
@ -161,11 +177,7 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
break;
case 'p' : /* Pointer value */
if ((format - bufformat + 1) > sizeof(tformat) ||
(width + 2) > sizeof(temp)) break;
strncpy(tformat, bufformat, (size_t)(format - bufformat));
tformat[format - bufformat] = '\0';
if ((width + 2) > sizeof(temp)) break;
sprintf(temp, tformat, va_arg(ap, void *));
@ -223,26 +235,7 @@ int fl_vsnprintf(char* buffer, size_t bufsize, const char* format, va_list ap) {
break;
case 'n' : /* Output number of chars so far */
if ((format - bufformat + 1) > sizeof(tformat) ||
(width + 2) > sizeof(temp)) break;
strncpy(tformat, bufformat, (size_t)(format - bufformat));
tformat[format - bufformat] = '\0';
sprintf(temp, tformat, va_arg(ap, int));
bytes += strlen(temp);
if (bufptr) {
if ((bufptr + strlen(temp)) > bufend) {
strncpy(bufptr, temp, (size_t)(bufend - bufptr));
bufptr = bufend;
break;
} else {
strcpy(bufptr, temp);
bufptr += strlen(temp);
}
}
*(va_arg(ap, int *)) = bytes;
break;
}
} else {

View File

@ -40,7 +40,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmtd"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\file_chooser_/file_chooserd.pdb"
SubSystem="2"
@ -105,7 +105,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmt"
ProgramDatabaseFile=".\Release/file_chooser.pdb"
SubSystem="2"
TargetMachine="1"/>

View File

@ -3,6 +3,7 @@
ProjectType="Visual C++"
Version="7.10"
Name="fltkforms"
ProjectGUID="{03B1D81E-6803-4DCD-8D2C-3758462EF9BA}"
SccProjectName=""
SccLocalPath="">
<Platforms>

View File

@ -3,6 +3,7 @@
ProjectType="Visual C++"
Version="7.10"
Name="fluid"
ProjectGUID="{CA3316EA-0D67-4463-A97E-F5578EAC5CC3}"
SccProjectName=""
SccLocalPath="">
<Platforms>
@ -40,7 +41,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmtd"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\fluid__0/fluidd.pdb"
SubSystem="2"
@ -106,7 +107,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmt"
ProgramDatabaseFile=".\fluid___/fluid.pdb"
SubSystem="2"
TargetMachine="1"/>

View File

@ -41,7 +41,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmt"
ProgramDatabaseFile=".\Release/help.pdb"
SubSystem="2"
TargetMachine="1"/>
@ -104,7 +104,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmtd"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\help_/helpd.pdb"
SubSystem="2"

View File

@ -40,7 +40,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmtd"
GenerateDebugInformation="TRUE"
ProgramDatabaseFile=".\pixmap_browser_/pixmap_browserd.pdb"
SubSystem="2"
@ -105,7 +105,7 @@
LinkIncremental="1"
SuppressStartupBanner="TRUE"
AdditionalLibraryDirectories="..\lib"
IgnoreDefaultLibraryNames="libcd"
IgnoreDefaultLibraryNames="libcmt"
ProgramDatabaseFile=".\Release/pixmap_browser.pdb"
SubSystem="2"
TargetMachine="1"/>

View File

@ -3,6 +3,7 @@
ProjectType="Visual C++"
Version="7.10"
Name="valuators"
ProjectGUID="{9D950D8D-CD7F-4163-8E57-65016DB10E3E}"
SccProjectName=""
SccLocalPath="">
<Platforms>