mirror of
git://git.code.sf.net/p/cdesktopenv/code
synced 2025-02-13 19:52:20 +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:
parent
0b36868c8c
commit
e8b3274a65
17 changed files with 62 additions and 36 deletions
|
@ -25,3 +25,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cmd.h>
|
#include <cmd.h>
|
||||||
|
|
||||||
|
// @lkoutsofios added to prevent this file from being optimized out
|
||||||
|
int _do_not_opt_out (void) {
|
||||||
|
sfprintf (sfstderr, "unreachable");
|
||||||
|
}
|
||||||
|
|
|
@ -1007,7 +1007,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
|
||||||
else if(i=='=' || (i=='\\' && out[cur-1]=='/'))
|
else if(i=='=' || (i=='\\' && out[cur-1]=='/'))
|
||||||
{
|
{
|
||||||
draw(ep,REFRESH);
|
draw(ep,REFRESH);
|
||||||
if(count>0)
|
if(count>0 || i=='\\')
|
||||||
ep->ed->e_tabcount=0;
|
ep->ed->e_tabcount=0;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|
|
@ -1183,6 +1183,10 @@ setfile(register Archive_t* ap, register File_t* f)
|
||||||
int m;
|
int m;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
|
|
||||||
|
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 (lchmod(f->name, f->perm & state.modemask))
|
if (lchmod(f->name, f->perm & state.modemask))
|
||||||
error(1, "%s: cannot chmod to %s", f->name, fmtmode(f->perm & state.modemask, 0) + 1);
|
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))
|
else if (m = f->perm & (S_ISUID|S_ISGID|S_ISVTX))
|
||||||
|
@ -1193,6 +1197,7 @@ setfile(register Archive_t* ap, register File_t* f)
|
||||||
error(1, "%s: mode %s not set", f->name, fmtmode(m, 0) + 1);
|
error(1, "%s: mode %s not set", f->name, fmtmode(m, 0) + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
ap->updated += updated;
|
ap->updated += updated;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -44,5 +44,10 @@ extern int resolvepath(const char*, char*, size_t);
|
||||||
extern char*
|
extern char*
|
||||||
realpath(const char* file, char* path)
|
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;
|
return resolvepath(file, path, PATH_MAX) > 0 ? path : (char*)0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,6 @@ cat{
|
||||||
#define _FILE_DEFINED 1
|
#define _FILE_DEFINED 1
|
||||||
#define _FILE_defined 1
|
#define _FILE_defined 1
|
||||||
#define _FILEDEFED 1
|
#define _FILEDEFED 1
|
||||||
#define __FILE_defined 1
|
|
||||||
#define ____FILE_defined 1
|
|
||||||
|
|
||||||
#ifndef __FILE_TAG
|
#ifndef __FILE_TAG
|
||||||
#define __FILE_TAG _sfio_s
|
#define __FILE_TAG _sfio_s
|
||||||
|
|
|
@ -191,7 +191,7 @@ tst malloc_hook note{ gnu malloc hooks work }end execute{
|
||||||
__realloc_hook = test_realloc_hook;
|
__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()
|
int main()
|
||||||
{
|
{
|
||||||
|
|
|
@ -58,21 +58,9 @@ struct _sfio_s;
|
||||||
#ifndef __FILE_typedef
|
#ifndef __FILE_typedef
|
||||||
#define __FILE_typedef 1
|
#define __FILE_typedef 1
|
||||||
#endif
|
#endif
|
||||||
#ifndef _FILE_DEFINED
|
|
||||||
#define _FILE_DEFINED 1
|
|
||||||
#endif
|
|
||||||
#ifndef _FILE_defined
|
|
||||||
#define _FILE_defined 1
|
|
||||||
#endif
|
|
||||||
#ifndef _FILEDEFED
|
#ifndef _FILEDEFED
|
||||||
#define _FILEDEFED 1
|
#define _FILEDEFED 1
|
||||||
#endif
|
#endif
|
||||||
#ifndef __FILE_defined
|
|
||||||
#define __FILE_defined 1
|
|
||||||
#endif
|
|
||||||
#ifndef ____FILE_defined
|
|
||||||
#define ____FILE_defined 1
|
|
||||||
#endif
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -76,6 +76,25 @@ struct _sfio_s;
|
||||||
#undef FILE
|
#undef FILE
|
||||||
#endif
|
#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 */
|
/* locale stuff */
|
||||||
|
|
||||||
#if !_hdr_locale
|
#if !_hdr_locale
|
||||||
|
|
|
@ -96,7 +96,7 @@ int c; /* if c>=0, c is also written out */
|
||||||
isall = SFISALL(f,isall);
|
isall = SFISALL(f,isall);
|
||||||
if((w = SFWR(f,data,n,f->disc)) > 0)
|
if((w = SFWR(f,data,n,f->disc)) > 0)
|
||||||
{ if((n -= w) > 0) /* save unwritten data, then resume */
|
{ 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;
|
written += w;
|
||||||
f->next = f->data+n;
|
f->next = f->data+n;
|
||||||
if(c < 0 && (!isall || n == 0))
|
if(c < 0 && (!isall || n == 0))
|
||||||
|
|
|
@ -190,7 +190,7 @@ reg int rc; /* record separator */
|
||||||
{ /* move left-over to read stream */
|
{ /* move left-over to read stream */
|
||||||
if(w > fr->size)
|
if(w > fr->size)
|
||||||
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;
|
fr->endb = fr->data+w;
|
||||||
if((w = endb - (cp+w)) > 0)
|
if((w = endb - (cp+w)) > 0)
|
||||||
(void)SFSK(fr,(Sfoff_t)(-w),SEEK_CUR,fr->disc);
|
(void)SFSK(fr,(Sfoff_t)(-w),SEEK_CUR,fr->disc);
|
||||||
|
@ -200,7 +200,7 @@ reg int rc; /* record separator */
|
||||||
{ if(direct == SF_WRITE)
|
{ if(direct == SF_WRITE)
|
||||||
fw->next += r;
|
fw->next += r;
|
||||||
else if(r <= (fw->endb-fw->next) )
|
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;
|
fw->next += r;
|
||||||
}
|
}
|
||||||
else if((w = SFWRITE(fw,(Void_t*)next,r)) != r)
|
else if((w = SFWRITE(fw,(Void_t*)next,r)) != r)
|
||||||
|
|
|
@ -138,7 +138,7 @@ int n; /* current position in pool */
|
||||||
else /* write failed, recover buffer then quit */
|
else /* write failed, recover buffer then quit */
|
||||||
{ if(w > 0)
|
{ if(w > 0)
|
||||||
{ v -= w;
|
{ v -= w;
|
||||||
memcpy(head->data,(head->data+w),v);
|
memmove(head->data,(head->data+w),v);
|
||||||
}
|
}
|
||||||
head->next = head->data+v;
|
head->next = head->data+v;
|
||||||
goto done;
|
goto done;
|
||||||
|
@ -147,7 +147,7 @@ int n; /* current position in pool */
|
||||||
|
|
||||||
/* move data from head to f */
|
/* move data from head to f */
|
||||||
if((head->data+k) != f->data )
|
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;
|
f->next = f->data+v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -201,7 +201,7 @@ Sfdisc_t* disc;
|
||||||
if(buf)
|
if(buf)
|
||||||
{ if(n > (size_t)(r-a))
|
{ if(n > (size_t)(r-a))
|
||||||
n = (ssize_t)(r-a);
|
n = (ssize_t)(r-a);
|
||||||
memcpy(buf,f->next,n);
|
memmove(buf,f->next,n);
|
||||||
f->next += n;
|
f->next += n;
|
||||||
}
|
}
|
||||||
else n = f->endb - f->next;
|
else n = f->endb - f->next;
|
||||||
|
|
|
@ -92,7 +92,7 @@ size_t n; /* number of bytes to be read. */
|
||||||
{ if(r > (ssize_t)n)
|
{ if(r > (ssize_t)n)
|
||||||
r = (ssize_t)n;
|
r = (ssize_t)n;
|
||||||
if(s != f->next)
|
if(s != f->next)
|
||||||
memcpy(s, f->next, r);
|
memmove(s, f->next, r);
|
||||||
f->next += r;
|
f->next += r;
|
||||||
s += r;
|
s += r;
|
||||||
n -= r;
|
n -= r;
|
||||||
|
|
|
@ -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.
|
/* 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! */
|
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)
|
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)
|
if(sc->f->endr == sc->f->endb)
|
||||||
sc->f->endr = sc->f->data+n;
|
sc->f->endr = sc->f->data+n;
|
||||||
if(sc->f->endw == sc->f->endb)
|
if(sc->f->endw == sc->f->endb)
|
||||||
|
|
|
@ -823,7 +823,7 @@ static void vm_initialize_hook(void)
|
||||||
__realloc_hook = vm_realloc_hook;
|
__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 */
|
#if 0 /* 2012-02-29 this may be needed to cover shared libs */
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static const char usage[] =
|
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
|
USAGE_LICENSE
|
||||||
"[+NAME?tail - output trailing portion of one or more files ]"
|
"[+NAME?tail - output trailing portion of one or more files ]"
|
||||||
"[+DESCRIPTION?\btail\b copies one or more input files to standard output "
|
"[+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;
|
Tail_t* files;
|
||||||
Tv_t tv;
|
Tv_t tv;
|
||||||
|
|
||||||
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
|
cmdinit(argc, argv, context, ERROR_CATALOG, ERROR_NOTIFY);
|
||||||
for (;;)
|
for (;;)
|
||||||
{
|
{
|
||||||
switch (n = optget(argv, usage))
|
switch (n = optget(argv, usage))
|
||||||
|
@ -639,7 +639,7 @@ b_tail(int argc, char** argv, Shbltin_t* context)
|
||||||
{
|
{
|
||||||
if (n)
|
if (n)
|
||||||
n = 0;
|
n = 0;
|
||||||
else if (sh_checksig(context) || tvsleep(&tv, NiL))
|
else if (sh_checksig(context) || tvsleep(&tv, NiL) && sh_checksig(context))
|
||||||
{
|
{
|
||||||
error_info.errors++;
|
error_info.errors++;
|
||||||
break;
|
break;
|
||||||
|
@ -686,11 +686,13 @@ b_tail(int argc, char** argv, Shbltin_t* context)
|
||||||
{
|
{
|
||||||
i = 3;
|
i = 3;
|
||||||
while (--i && stat(fp->name, &st))
|
while (--i && stat(fp->name, &st))
|
||||||
if (sh_checksig(context) || tvsleep(&tv, NiL))
|
if (sh_checksig(context))
|
||||||
{
|
{
|
||||||
error_info.errors++;
|
error_info.errors++;
|
||||||
goto done;
|
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 (i && (fp->dev != st.st_dev || fp->ino != st.st_ino) && !init(fp, 0, 0, flags, &format))
|
||||||
{
|
{
|
||||||
if (!(flags & SILENT))
|
if (!(flags & SILENT))
|
||||||
|
|
|
@ -49,6 +49,10 @@
|
||||||
#include <exparse.h>
|
#include <exparse.h>
|
||||||
#if defined(YYSTYPE) || defined(yystype)
|
#if defined(YYSTYPE) || defined(yystype)
|
||||||
#define EXSTYPE YYSTYPE
|
#define EXSTYPE YYSTYPE
|
||||||
|
#else
|
||||||
|
#if defined(YYSTYPE) || defined(YYSTYPE_IS_DECLARED)
|
||||||
|
#define EXSTYPE YYSTYPE
|
||||||
|
#endif
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue