* A strang alpha bug
@ 1997-10-13 15:02 H.J. Lu
0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 1997-10-13 15:02 UTC (permalink / raw)
To: egcs
On alpha, I got
# gcc inline.cc
# a.out
# gcc -O inline.cc
# a.out
Aborted (core dumped)
# gcc -O inline.cc -fno-exceptions
# a.out
It seems that the exception handling is messing up something.
--
H.J. Lu (hjl@gnu.ai.mit.edu)
---inline.cc--
#include <new.h>
typedef struct
{
unsigned short len;
unsigned short sz;
char s[1];
} Rep;
inline static void ncopy0(const char* from, char* to, int n)
{
if (from != to)
{
while (--n >= 0) *to++ = *from++;
*to = 0;
}
else
to[n] = 0;
}
inline static int slen(const char* t) // inline strlen
{
if (t == 0)
return 0;
else
{
const char* a = t;
while (*a++ != 0);
return a - 1 - t;
}
}
inline static Rep* Snew(int newsiz)
{
if (newsiz == -1)
abort ();
Rep* rep = new (operator new (sizeof(Rep) + newsiz)) Rep;
rep->sz = newsiz;
return rep;
}
Rep *
copy (Rep *old, const char *src, int srclen, int newlen)
{
if (srclen < 0) srclen = slen (src);
if (newlen < srclen) newlen = srclen;
Rep* rep;
if (old == 0 || newlen > old->sz)
{
rep = Snew (newlen);
}
else
rep = old;
rep->len = newlen;
ncopy0(src, rep->s, srclen);
return rep;
}
main ()
{
Rep *rep = copy (0, "Hello", -1, -1);
exit (0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
* A strang alpha bug
@ 1998-02-20 16:12 H.J. Lu
0 siblings, 0 replies; 2+ messages in thread
From: H.J. Lu @ 1998-02-20 16:12 UTC (permalink / raw)
To: egcs
On alpha, I got
# gcc inline.cc
# a.out
# gcc -O inline.cc
# a.out
Aborted (core dumped)
# gcc -O inline.cc -fno-exceptions
# a.out
It seems that the exception handling is messing up something.
--
H.J. Lu (hjl@gnu.ai.mit.edu)
---inline.cc--
#include <new.h>
typedef struct
{
unsigned short len;
unsigned short sz;
char s[1];
} Rep;
inline static void ncopy0(const char* from, char* to, int n)
{
if (from != to)
{
while (--n >= 0) *to++ = *from++;
*to = 0;
}
else
to[n] = 0;
}
inline static int slen(const char* t) // inline strlen
{
if (t == 0)
return 0;
else
{
const char* a = t;
while (*a++ != 0);
return a - 1 - t;
}
}
inline static Rep* Snew(int newsiz)
{
if (newsiz == -1)
abort ();
Rep* rep = new (operator new (sizeof(Rep) + newsiz)) Rep;
rep->sz = newsiz;
return rep;
}
Rep *
copy (Rep *old, const char *src, int srclen, int newlen)
{
if (srclen < 0) srclen = slen (src);
if (newlen < srclen) newlen = srclen;
Rep* rep;
if (old == 0 || newlen > old->sz)
{
rep = Snew (newlen);
}
else
rep = old;
rep->len = newlen;
ncopy0(src, rep->s, srclen);
return rep;
}
main ()
{
Rep *rep = copy (0, "Hello", -1, -1);
exit (0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-02-20 16:12 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-10-13 15:02 A strang alpha bug H.J. Lu
1998-02-20 16:12 H.J. Lu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).