summaryrefslogtreecommitdiffstats
path: root/bin/sh/memalloc.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Remove linked list of stack marks.jilles2013-05-111-17/+3
| | | | | | | | | | | | | | | | The linked list of stack marks may cause problems if the allocation stack is used between an exception and a higher-level popstackmark(), as it may then touch a stack mark that is local to a function which has returned. Also, the adjustment compares to a pointer passed to realloc(), which is undefined behaviour. Instead of adjusting stack marks when reallocating stack blocks, ensure that such an adjustment is never necessary by fixing a small piece of memory in place at a stack mark. This also simplifies the code. To avoid the problems reported in bin/175922, it remains necessary to call setstackmark() after popstackmark() if the stack mark remains in use.
* sh: Fix various compiler warnings.jilles2013-04-011-2/+3
| | | | | | | It now passes WARNS=7 with clang on i386. GCC 4.2.1 does not understand setjmp() properly so will always trigger -Wuninitialized. I will not add the volatile keywords to suppress this.
* sh: Follow-up to r216743, grabstackblock() can be replaced with stalloc().jilles2011-01-091-10/+0
| | | | | grabstackblock() was used only once (but it is a very often executed piece of code).
* sh: Simplify "stack string" code slightly.jilles2010-12-271-15/+6
| | | | | | | Maintain a pointer to the end of the stack string area instead of how much space is left. This simplifies the macros in memalloc.h. The places where the new variable must be updated are only where the memory area is created, destroyed or resized.
* sh: Fix integer overflow check, it checked an uninitialized variable.jilles2010-12-261-1/+1
|
* sh: Allow arbitrary large numbers in CHECKSTRSPACE.jilles2010-12-261-14/+21
| | | | | | Reduce "stack string" API somewhat and simplify code. Add a check for integer overflow of the "stack string" length (probably incomplete).
* sh: Remove the herefd hack.jilles2010-12-121-6/+0
| | | | | | | | | | | | | | | | | | The herefd hack wrote out partial here documents while expanding them. It seems unnecessary complication given that other expansions just allocate memory. It causes bugs because the stack is also used for intermediate results such as arithmetic expressions. Such places should disable herefd for the duration but not all of them do, and I prefer removing the need for disabling herefd to disabling it everywhere needed. Here documents larger than 1024 bytes will use a bit more CPU time and memory. Additionally this allows a later change to expand here documents in the current shell environment. (This is faster for small here documents but also changes behaviour.) Obtained from: dash
* sh: Code size optimizations to "stack string" memory allocation:jilles2010-11-231-0/+17
| | | | | | | | * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string. No functional change is intended, but code size is about 1K less on i386.
* Do not assume in growstackstr() that a "precious" character will beobrien2010-10-131-7/+10
| | | | | | | | | | | | | | | | immediately written into the stack after the call. Instead let the caller manage the "space left". Previously, growstackstr()'s assumption causes problems with STACKSTRNUL() where we want to be able to turn a stack into a C string, and later pretend the NUL is not there. This fixes a bug in STACKSTRNUL() (that grew the stack) where: 1. STADJUST() called after a STACKSTRNUL() results in an improper adjust. This can be seen in ${var%pattern} and ${var%%pattern} evaluation. 2. Memory leak in STPUTC() called after a STACKSTRNUL(). Reviewed by: jilles
* In the spirit of r90111, depend on c89 and remove the "STATIC" macroobrien2010-10-131-1/+1
| | | | and its usage.
* Consistently use "STATIC" for all functions in order to be able to setobrien2010-10-131-3/+3
| | | | | | breakpoints with in a debugger. And use naked "static" for variables. Noticed by: bde
* sh: Constify various strings.jilles2009-12-241-1/+1
| | | | | Most of this is adding const keywords, but setvar() in var.c had to be changed somewhat more.
* be more type correct and align local ckmalloc() with its underlying ↵rse2009-06-011-1/+1
| | | | malloc(3) by using a "size_t" instead of an "int" argument
* Protect malloc, realloc and free calls with INT{ON,OFF} directly in chkalloc,stefanf2005-10-281-2/+16
| | | | | | | | | | | | | | ckrealloc and ckfree (added), respectively. sh jumps out of the signal handler using longjmp which is obviously a bad idea during malloc calls. Note: I think there is still a small race here because volatile sig_atomic_t only guarantees atomic reads and writes while we're doing increments and decrements. Protect a setmode call with INT{ON,OFF} as it calls malloc internally. PR: 45478 Patch from: Nate Eldredge
* Remove clause 3 from the UCB licenses.markm2004-04-061-4/+0
| | | | OK'ed by: imp, core
* Changes following CScout analysis:dds2003-07-051-2/+2
| | | | | | | | | | | - Removed dead declarations - Made objects that should have been declared as static, static. The changes use STATIC instead of static, following the existing convention in the rest of the code. Approved by: schweikh (mentor) MFC after: 2 weeks
* Third attempt at removing machdep.h and using ALIGN from <sys/param.h>.marcel2003-02-241-48/+53
| | | | | | | | | | | | | | The initial stack_block is staticly allocated and will be aligned according to the alignment requirements of pointers, which does not necessarily match the alignment enforced by ALIGN. To solve this a more involved change is required: remove the static initial stack and deal with an initial condition of not having a stack at all. This change is therefore more risky than the previous ones, but unavoidable (other than not using the platform default alignment). Discussed with: tjr Approved and reviewed by: tjr Tested on: alpha, i386, ia64 and sparc64
* Revert ALIGN change for the second and last time. I can't figure outtjr2003-02-181-4/+3
| | | | why this is breaking sparc64.
* Second attempt at removing machdep.h and using ALIGN from <sys/param.h>.tjr2003-02-171-3/+4
| | | | | | The problem with the previous attempt, as noticed by Marcel, was that stacknxt was being aligned to a pointer boundary instead of an ALIGNBYTES + 1 boundary, which broke sparc64.
* Temporarily back out machdep.h/ALIGN changes. It seems that on sparc64,tjr2003-02-161-2/+1
| | | | | | using the alignment from sys/param.h (16) instead of the alignment from machdep.h (8) tickled a nasty bug in the memory allocator that I haven't been able to track down yet.
* Use the ALIGN macro from <sys/param.h> instead of defining our owntjr2003-02-141-1/+2
| | | | incorrect version in machdep.h. Delete machdep.h.
* Consistently use FBSDIDobrien2002-06-301-2/+2
|
* o __P has been reovedimp2002-02-021-23/+12
| | | | | | | | | | | | | | | | | | o Old-style K&R declarations have been converted to new C89 style o register has been removed o prototype for main() has been removed (gcc3 makes it an error) o int main(int argc, char *argv[]) is the preferred main definition. o Attempt to not break style(9) conformance for declarations more than they already are. o Change int foo() { ... to int foo(void) { ...
* Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. Thesheldonh2001-07-261-1/+1
| | | | | | | definitions are more readable, and it's possible that they're more portable to pathalogical platforms. Submitted by: David Hill <david@phobia.ms>
* From submitter:cracauer2000-08-161-0/+19
| | | | | | | | | | | | | | | | | growstackblock() sometimes relocates a stack_block considered empty without properly relocating stack marks referencing that block. The first call to popstackmark() with the unrelocated stack mark as argument then causes sh to abort. Relocating the relevant stack marks seems to solve this problem. The patch changes the semantics of popstackmark() somewhat. It can only be called once after a call to setstackmark(), thus cmdloop() in main.c needs an extra call to setstackmark(). PR: bin/19983 Submitted by: Tor.Egge@fast.no Reviewed by: Gerald Pfeifer <pfeifer@dbai.tuwien.ac.at>
* $Id$ -> $FreeBSD$peter1999-08-271-1/+1
|
* Remove my temporary detection for PR 7059, Tor Egge fixed this bug.cracauer1999-04-131-5/+1
| | | | PR: 7059
* Add a guarded abort() for the problem in PR bin/7059 (no fix so far,cracauer1999-04-121-17/+33
| | | | | | | | this is hairy). Reformat this file to comply to style(9). It had mixed styles before. PR: bin/7059
* Be more consistent with handling of quote mark control character.tegge1998-09-131-2/+2
| | | | | | | Don't output double-quotes inside variable expansion/arithmetic expansion region in here-documents. When leaving the arithmetic expansion syntax mode, adjust the dblquote flag according to previous syntax, in order to avoid splitting of quoted variables.
* Fix an inefficiency I introduced in my last commit.cracauer1998-09-101-1/+2
| | | | Include "expand.h" vom memalloc.c to pull function declartion into scope
* Better handling of word splitting. Don't record the same regiontegge1998-09-061-2/+2
| | | | | | multiple times when performing nested variable expansion, and preserve some quoting information in order to avoid removing apparently empty expansion result.
* Add rcsid. Spelling.charnier1998-05-181-3/+5
|
* Nuke register keyword usage and #if -> #ifdef.steve1997-04-281-5/+5
| | | | Obtained from: NetBSD
* Revert $FreeBSD$ to $Id$peter1997-02-221-1/+1
|
* Make the long-awaited change from $Id$ to $FreeBSD$jkh1997-01-141-1/+1
| | | | | | | | This will make a number of things easier in the future, as well as (finally!) avoiding the Id-smashing problem which has plagued developers for so long. Boy, I'm glad we're not using sup anymore. This update would have been insane otherwise.
* Merge in NetBSD mods and -Wall cleaning.steve1996-12-141-5/+5
| | | | Obtained from: NetBSD, me
* Fix for PR#1287. This makes sh behave sensibly in case statements in thepeter1996-09-031-3/+3
| | | | | | | | | | | | | | face of aliases. Note, bash doesn't do aliases while running scripts, but "real" ksh does.. Also: Reduce redundant .Nm macros in (unused) bltin/echo.1 nuke error2, it's hardly used. More -Wall cleanups dont do certain history operations if NO_HISTORY defined handle quad_t's from resource limits Submitted by: Steve Price <sprice@hiwaay.net> (minor tweaks by me)
* Merge of 4.4-Lite2 sh source, plus some gcc -Wall cleaning. This is apeter1996-09-011-10/+17
| | | | | | | | | | | | | | merge of parallel duplicate work by Steve Price and myself. :-] There are some changes to the build that are my fault... mkinit.c was trying (poorly) to duplicate some of the work that make(1) is designed to do. The Makefile hackery is my fault too, the depend list was incomplete because of some explicit OBJS+= entries, so mkdep wasn't picking up their source file #includes. This closes a pile of /bin/sh PR's, but not all of them.. Submitted by: Steve Price <steve@bonsai.hiwaay.net>, peter
* Added $Id$dg1994-09-241-0/+2
|
* BSD 4.4 Lite bin Sourcesrgrimes1994-05-261-0/+292
OpenPOWER on IntegriCloud