1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 11:42:21 +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

@ -25,3 +25,8 @@
*/
#include <cmd.h>
// @lkoutsofios added to prevent this file from being optimized out
int _do_not_opt_out (void) {
sfprintf (sfstderr, "unreachable");
}

View file

@ -1007,7 +1007,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
else if(i=='=' || (i=='\\' && out[cur-1]=='/'))
{
draw(ep,REFRESH);
if(count>0)
if(count>0 || i=='\\')
ep->ed->e_tabcount=0;
else
{

View file

@ -1183,14 +1183,19 @@ setfile(register Archive_t* ap, register File_t* f)
int m;
struct stat st;
if (lchmod(f->name, f->perm & state.modemask))
error(1, "%s: cannot chmod to %s", f->name, fmtmode(f->perm & state.modemask, 0) + 1);
else if (m = f->perm & (S_ISUID|S_ISGID|S_ISVTX))
if (lstat(f->name, &st))
error(1, "%s: not found", f->name);
else if ((f->perm ^ st.st_mode) & state.modemask & (S_ISUID|S_ISGID|S_ISVTX|S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH))
{
if (lstat(f->name, &st))
error(1, "%s: not found", f->name);
else if (m ^= (st.st_mode & (S_ISUID|S_ISGID|S_ISVTX)))
error(1, "%s: mode %s not set", f->name, fmtmode(m, 0) + 1);
if (lchmod(f->name, f->perm & state.modemask))
error(1, "%s: cannot chmod to %s", f->name, fmtmode(f->perm & state.modemask, 0) + 1);
else if (m = f->perm & (S_ISUID|S_ISGID|S_ISVTX))
{
if (lstat(f->name, &st))
error(1, "%s: not found", f->name);
else if (m ^= (st.st_mode & (S_ISUID|S_ISGID|S_ISVTX)))
error(1, "%s: mode %s not set", f->name, fmtmode(m, 0) + 1);
}
}
}
#endif

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 */

View file

@ -28,7 +28,7 @@
*/
static const char usage[] =
"+[-?\n@(#)$Id: tail (AT&T Research) 2012-06-19 $\n]"
"+[-?\n@(#)$Id: tail (AT&T Research) 2012-10-10 $\n]"
USAGE_LICENSE
"[+NAME?tail - output trailing portion of one or more files ]"
"[+DESCRIPTION?\btail\b copies one or more input files to standard output "
@ -424,7 +424,7 @@ b_tail(int argc, char** argv, Shbltin_t* context)
Tail_t* files;
Tv_t tv;
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY);
for (;;)
{
switch (n = optget(argv, usage))
@ -639,7 +639,7 @@ b_tail(int argc, char** argv, Shbltin_t* context)
{
if (n)
n = 0;
else if (sh_checksig(context) || tvsleep(&tv, NiL))
else if (sh_checksig(context) || tvsleep(&tv, NiL) && sh_checksig(context))
{
error_info.errors++;
break;
@ -686,11 +686,13 @@ b_tail(int argc, char** argv, Shbltin_t* context)
{
i = 3;
while (--i && stat(fp->name, &st))
if (sh_checksig(context) || tvsleep(&tv, NiL))
if (sh_checksig(context))
{
error_info.errors++;
goto done;
}
else
tvsleep(&tv, NiL);
if (i && (fp->dev != st.st_dev || fp->ino != st.st_ino) && !init(fp, 0, 0, flags, &format))
{
if (!(flags & SILENT))

View file

@ -49,6 +49,10 @@
#include <exparse.h>
#if defined(YYSTYPE) || defined(yystype)
#define EXSTYPE YYSTYPE
#else
#if defined(YYSTYPE) || defined(YYSTYPE_IS_DECLARED)
#define EXSTYPE YYSTYPE
#endif
#endif
#endif