1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

C code bug fixes

- fix to buildin.c to prevent compiler from optimizing it out
- fix to realpath.c to handle case where 'path' is NULL

- fix to emacs.c (I think from dgk)

- fix to file.c (I think from gsf)
- fix to tail.c (I think from gsf)

- fix to code setting the malloc init hook (for vmalloc)

- changed memcpy to memmove in several places in sfio because src and dst
  might overlap

- fixes to macros like FILE_defined to fix header file issues
- fixes to expr.h to handle macro definition issue
This commit is contained in:
Lefteris Koutsofios 2020-02-12 13:09:47 -05:00
parent 0b36868c8c
commit e8b3274a65
17 changed files with 62 additions and 36 deletions

View file

@ -44,5 +44,10 @@ extern int resolvepath(const char*, char*, size_t);
extern char*
realpath(const char* file, char* path)
{
// @lkoutsofios path may be NULL
if (!path) {
if (!(path = malloc (PATH_MAX)))
return NULL;
}
return resolvepath(file, path, PATH_MAX) > 0 ? path : (char*)0;
}

View file

@ -6,8 +6,6 @@ cat{
#define _FILE_DEFINED 1
#define _FILE_defined 1
#define _FILEDEFED 1
#define __FILE_defined 1
#define ____FILE_defined 1
#ifndef __FILE_TAG
#define __FILE_TAG _sfio_s

View file

@ -191,7 +191,7 @@ tst malloc_hook note{ gnu malloc hooks work }end execute{
__realloc_hook = test_realloc_hook;
}
void (*__malloc_initialize_hook)(void) = test_initialize_hook;
typeof (__malloc_initialize_hook) __malloc_initialize_hook = test_initialize_hook;
int main()
{

View file

@ -58,21 +58,9 @@ struct _sfio_s;
#ifndef __FILE_typedef
#define __FILE_typedef 1
#endif
#ifndef _FILE_DEFINED
#define _FILE_DEFINED 1
#endif
#ifndef _FILE_defined
#define _FILE_defined 1
#endif
#ifndef _FILEDEFED
#define _FILEDEFED 1
#endif
#ifndef __FILE_defined
#define __FILE_defined 1
#endif
#ifndef ____FILE_defined
#define ____FILE_defined 1
#endif
#endif
/*

View file

@ -76,6 +76,25 @@ struct _sfio_s;
#undef FILE
#endif
#ifndef FILE
#ifndef _SFIO_H
struct _sfio_s;
#endif
#define FILE struct _sfio_s
#ifndef __FILE_typedef
#define __FILE_typedef 1
#endif
#ifndef _FILEDEFED
#define _FILEDEFED 1
#endif
#ifndef ____FILE_defined
#define ____FILE_defined 1
#endif
#ifndef __FILE_defined
#define __FILE_defined 1
#endif
#endif
/* locale stuff */
#if !_hdr_locale

View file

@ -96,7 +96,7 @@ int c; /* if c>=0, c is also written out */
isall = SFISALL(f,isall);
if((w = SFWR(f,data,n,f->disc)) > 0)
{ if((n -= w) > 0) /* save unwritten data, then resume */
memcpy((char*)f->data,(char*)data+w,n);
memmove((char*)f->data,(char*)data+w,n);
written += w;
f->next = f->data+n;
if(c < 0 && (!isall || n == 0))

View file

@ -190,7 +190,7 @@ reg int rc; /* record separator */
{ /* move left-over to read stream */
if(w > fr->size)
w = fr->size;
memcpy((Void_t*)fr->data,(Void_t*)cp,w);
memmove((Void_t*)fr->data,(Void_t*)cp,w);
fr->endb = fr->data+w;
if((w = endb - (cp+w)) > 0)
(void)SFSK(fr,(Sfoff_t)(-w),SEEK_CUR,fr->disc);
@ -200,7 +200,7 @@ reg int rc; /* record separator */
{ if(direct == SF_WRITE)
fw->next += r;
else if(r <= (fw->endb-fw->next) )
{ memcpy((Void_t*)fw->next,(Void_t*)next,r);
{ memmove((Void_t*)fw->next,(Void_t*)next,r);
fw->next += r;
}
else if((w = SFWRITE(fw,(Void_t*)next,r)) != r)

View file

@ -138,7 +138,7 @@ int n; /* current position in pool */
else /* write failed, recover buffer then quit */
{ if(w > 0)
{ v -= w;
memcpy(head->data,(head->data+w),v);
memmove(head->data,(head->data+w),v);
}
head->next = head->data+v;
goto done;
@ -147,7 +147,7 @@ int n; /* current position in pool */
/* move data from head to f */
if((head->data+k) != f->data )
memcpy(f->data,(head->data+k),v);
memmove(f->data,(head->data+k),v);
f->next = f->data+v;
}

View file

@ -201,7 +201,7 @@ Sfdisc_t* disc;
if(buf)
{ if(n > (size_t)(r-a))
n = (ssize_t)(r-a);
memcpy(buf,f->next,n);
memmove(buf,f->next,n);
f->next += n;
}
else n = f->endb - f->next;

View file

@ -92,7 +92,7 @@ size_t n; /* number of bytes to be read. */
{ if(r > (ssize_t)n)
r = (ssize_t)n;
if(s != f->next)
memcpy(s, f->next, r);
memmove(s, f->next, r);
f->next += r;
s += r;
n -= r;

View file

@ -247,7 +247,7 @@ Void_t* mbs; /* multibyte parsing state */
/* shift left data so that there will be more room to back up on error.
this won't help streams with small buffers - c'est la vie! */
if(sc->d > sc->f->data && (n = sc->endd - sc->d) > 0 && n < SFMBMAX)
{ memcpy(sc->f->data, sc->d, n);
{ memmove(sc->f->data, sc->d, n);
if(sc->f->endr == sc->f->endb)
sc->f->endr = sc->f->data+n;
if(sc->f->endw == sc->f->endb)

View file

@ -823,7 +823,7 @@ static void vm_initialize_hook(void)
__realloc_hook = vm_realloc_hook;
}
void (*__malloc_initialize_hook)(void) = vm_initialize_hook;
typeof (__malloc_initialize_hook) __malloc_initialize_hook = vm_initialize_hook;
#if 0 /* 2012-02-29 this may be needed to cover shared libs */