mfbt/IntegerPrintfMacros.h

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
     4  * You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 /* Implements the C99 <inttypes.h> interface, minus the SCN* format macros. */
     8 #ifndef mozilla_IntegerPrintfMacros_h_
     9 #define mozilla_IntegerPrintfMacros_h_
    11 /*
    12  * MSVC++ doesn't include <inttypes.h>, even in versions shipping <stdint.h>, so
    13  * we have to reimplement it there.  Note: <inttypes.h> #includes <stdint.h>.
    14  *
    15  * Note that this header DOES NOT implement <inttypes.h>'s scanf macros.  MSVC's
    16  * scanf doesn't have sufficient format specifier support to implement them
    17  * (specifically, to implement scanning into an 8-bit location).
    18  *
    19  * http://stackoverflow.com/questions/3036396/scanfd-char-char-as-int-format-string
    20  *
    21  * Moreover, scanf is a footgun: if the input number exceeds the bounds of the
    22  * target type, behavior is undefined (in the compiler sense: that is, this code
    23  * could overwrite your hard drive with zeroes):
    24  *
    25  *   uint8_t u;
    26  *   sscanf("256", "%" SCNu8, &u); // BAD
    27  *
    28  * This header will sometimes provide SCN* macros, by dint of being implemented
    29  * using <inttypes.h>.  But for these reasons, *never* use them!
    30  */
    32 #if defined(MOZ_CUSTOM_INTTYPES_H)
    33 #  include MOZ_CUSTOM_INTTYPES_H
    34 #elif defined(_MSC_VER)
    35 #  include "mozilla/MSIntTypes.h"
    36 #else
    37 #  include <inttypes.h>
    38 #endif
    40 #endif  /* mozilla_IntegerPrintfMacros_h_ */

mercurial