Re: hypenator.cc errors
Jorge Arellano Cid <[email protected]>
| Newsgroups | gmane.comp.web.dillo.devel |
|---|---|
| Message-ID | <[email protected]> |
On Fri, Sep 06, 2013 at 11:46:10AM +0200, Sebastian Geerken wrote: > > > [...] > > > > Thinking about it again, variable length arrays are a feature of C, > > but not of C++, although it seems that most C++ compilers support it. > > Since this is a nice feature, but standard C++ should be supported, > > I've thought of testing it by the configure script, and then hide two > > different implementations behind a macro. See attached patch, which > > should be applied to the current hg repository. > > > > What do you think? [...] > > Third round: I agree with Jorge that this is quite too complex; and > profiling shows no performance gain of using the heap over using the > stack, so I've replaced it by new and delete. Cris: please test the > latest version from hg, it should compile now. There's a memory problem with the sizeof(buf) because it returns the pointer size, not the array length! Please see the attached test case for details. (Compile with: g++ -W -Wall size3.cc -o size3) -- Cheers Jorge.- _______________________________________________ Dillo-dev mailing list [email protected] http://lists.auriga.wearlab.de/cgi-bin/mailman/listinfo/dillo-dev
size3.cc
(text/x-c++src, 887 B)
#include <stdio.h>
#include <string.h>
int main(void)
{
const char *patFile="/home/somewhere";
char *buf1 = new char[strlen (patFile) + 5 + 1];
/* Bug */
printf("strlen (patFile): %lu\n", strlen(patFile));
printf("strlen (buf1): %lu\n", strlen(buf1));
printf("sizeof (buf1): %lu\n", sizeof(buf1));
printf("sizeof (*buf1): %lu\n", sizeof(*buf1));
snprintf(buf1, sizeof (buf1), "%s.trie", patFile);
printf("buf1: %s\n\n", buf1);
/* OK */
size_t buf2len = strlen (patFile) + 5 + 1;
char *buf2 = new char[buf2len];
printf("strlen (patFile): %lu\n", strlen(patFile));
printf("strlen (buf2): %lu\n", strlen(buf2));
printf("sizeof (buf2): %lu\n", sizeof(buf2));
printf("sizeof (*buf2): %lu\n", sizeof(*buf2));
snprintf(buf2, buf2len, "%s.trie", patFile);
printf("buf2: %s\n", buf2);
delete[] buf2;
delete[] buf1;
return 0;
}