[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a simple snprintf truncating test
From: |
James A Morrison |
Subject: |
a simple snprintf truncating test |
Date: |
Fri, 27 Jul 2001 18:08:40 -0400 (EDT) |
Hi,
Here is a really simple program that shows whether snprintf
truncates properly. So far Solaris 5.6 acts the way I except it too.
James Morrison
#include <stdio.h>
/* A simple program to see if snprintf truncates properly */
int main(int argc, char* argv[]) {
char* test;
int retval=0;
snprintf(test,5,"1234");
if (!strcmp(test,"1234\0")) {
printf("Same length: Passed\n");
} else {
printf("Same length: Failed\n");
retval++;
}
snprintf(test,5,"123");
if(!strcmp(test,"123\0")) {
printf("Shorter: Passed\n");
} else {
printf("Shorter: Failed\n");
retval++;
}
snprintf(test,5,"123456");
if(!strcmp(test,"1234\0")) {
printf("Longer: Passed\n");
} else {
printf("Longer: Failed\n");
retval++;
}
return retval;
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- a simple snprintf truncating test,
James A Morrison <=