Everything2
Near Matches
Ignore Exact
Full Text
Everything2

unsigned

created by zatoichi

(thing) by zatoichi (4.2 y) (print)   ?   (I like it!) Sun Jul 02 2000 at 14:35:23

A number that does not extend to the negative side of zero. In terms of computer programming, an unsigned type does not use one of its bits to indicate positivity or negativity allowing it to hold larger values.

Also, the state of leaving a letter or other form of correspondance without a signature.

(thing) by ariels (14.4 hr) (print)   ?   (I like it!) Sat Apr 24 2004 at 17:20:38

(C (and thereby C++ and friends)

C defines signed and unsigned variants of the basic integer types. You apply the unsigned modifier to a type to specifiy that it is, indeed, unsigned. By default all integer types except char are signed; thus you must specify unsigned if you wish them to be so. char may or may not be signed by default, so you also need to specify unsigned if you specifically need this property.

Thus, after taking into account that int is optional, we have these "unsigned types":

  • unsigned char
  • unsigned short int or unsigned short
  • unsigned int or unsigned
  • unsigned long int or unsigned long
  • unsigned long long int or unsigned long long
Additionally, certain types defined in standard header files -- most notably size_t -- are unsigned. Decimal integer literals can be specified unsigned by appending a u.

All unsigned types can only hold values ≥0. Conversion to unsigned is implicit, and can be very dangerous (see below). Unsigned integer operations are considerably simpler than their signed cousins:

DANGER!

Unanticipated conversion to unsigned types is a common cause for security problems. For example, suppose a received packet of data consists of a length (2 bytes) followed by at most 8K of data. One is tempted to write

void *malloc(int);
unsigned char* get_buffer(unsigned char *buf)
{
  short len;
  unsigned char *ret;         /* No more than 32K read */
  len = buf[0]<<8 + buf[1];
  /* Ensure no buffer overflow */
  if (len > (1<<13))
    return NULL;
  ret = malloc(len);          /* DANGER! */
  memcpy(ret, buf+2, len);
  return ret;
}
This code checks to see it's not going to be tricked into copying too much data into ret. Unfortunately, the check fails. Suppose shorts are 2 bytes -- a common enough occurrence. If an attacker specifies a buffer of size 0xfffe, then len==-2, and -2<1<<13. We go on to malloc space. But the argument of malloc is really a size_t, and implicit conversion means we ask for 0xfffffffe bytes of memory. Oops.

ANY arithmetic mixing signed and unsigned operands is suspect. Particularly when one of the operands can be controlled from outside the program. Be careful!


printable version
chaos

Funny C declarations signed MD5 hash function 14233221
char** C Data Types wraparound Malignus Youth
Division Algorithm sign bit size_t Byte
Deathmatch: e vs pi socklen_t unsigned band AIM script kiddies
Boolean in BASIC floating point addiction 65535 &lt;&lt; operator
flag overflow Multiplication algorithm extern "C"
Y'know, if you log in, you can write something here, or contact authors directly on the site. Create a New User if you don't already have an account.
  Epicenter
Login
Password

password reminder
register

Everything2 Help

Cool Staff Picks
Nodes to live by:
Dumpling
He-Man and the Masters of the Universe
Nystagmus
How to tenderize an octopus
The Wind in the Willows
Live and Let Die
Sanctity of marriage
citizen's arrest
The Microsoft Sound
Paul is dead
How many grooves are on a record?
More 9/11 Conspiracy Theories
models of fictional time travel physics
New Writeups
Alnilamski
Rebel Yell(thing)
Heisenberg
Dahon Speed D7(thing)
etgar
Protection of civil rights in the USA and UK(essay)
archiewood
Airspace classifications(idea)
Ouzo
My first Christmas(event)
TheDeadGuy
Editor Log: August 2008(log)
AspieDad
Tools of the Trade(essay)
Apatrix
Editor Log: August 2008(log)
etouffee
Back where we started(poetry)
NeverLost
I'm never getting drunk again(idea)
Noung
post-racial(idea)
Heitah
Intensive farming(essay)
XWiz
Big Science(review)
Wuukiee
yellow cake batter(recipe)
Pavlovna
Sassenach(person)
Everything 2 is brought to you by the letter C and The Everything Development Company