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 (16 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
Drink up!
Leonard Koan
Black, not Hispanic
apostrophe
Eggnog
Indian Removal Act
English As She Is Spoke
Civilization
Love letter of housekeeping
A community without shame has no future
Astrophotography
Trieste
This program has performed an illegal operation and will be shut down
How to smoke a cigar
New Writeups
Ysardo
a brother to a sister(personal)
antigravpussy
your warm whispers(personal)
Clarke
Multiculturalism(idea)
aneurin
Earl of Landaff(person)
Heitah
Pseudocide(idea)
XWiz
Google Knol(lede)
Mythi
July 24, 2008(personal)
locke baron
The fall of Earth(fiction)
BookReader
Fear the Cold(dream)
Pavlovna
Kathleen MacInnes(person)
stainedglass
1(fiction)
kalen
Three "T"s(idea)
octillion369
Undead(idea)
archiewood
Ico(fiction)
Heisenberg
Why I love Everything2(log)
Everything 2 is brought to you by the letter C and The Everything Development Company