Changeset 20 for trunk/src/slib.c
- Timestamp:
- Feb 13, 2006, 11:54:42 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/slib.c
r12 r20 6 6 #include <stdarg.h> 7 7 #include <string.h> 8 8 #include <limits.h> 9 9 10 10 #include <unistd.h> … … 98 98 static FILE * trace_fp = NULL; 99 99 100 int sl_trace_use (c har * dummy)100 int sl_trace_use (const char * dummy) 101 101 { 102 102 if (dummy) … … 107 107 } 108 108 109 int sl_trace_file (c har * str)109 int sl_trace_file (const char * str) 110 110 { 111 111 if (!str) … … 1638 1638 1639 1639 static 1640 int sl_open_file (c har *filename, int mode, int priv)1640 int sl_open_file (const char *filename, int mode, int priv) 1641 1641 { 1642 1642 struct stat lbuf; … … 1848 1848 1849 1849 static 1850 int check_fname_priv (c har * fname, int priv)1850 int check_fname_priv (const char * fname, int priv) 1851 1851 { 1852 1852 SL_ENTER(_("check_fname_priv")); … … 1858 1858 } 1859 1859 1860 SL_TICKET sl_open_write (c har * fname, int priv)1860 SL_TICKET sl_open_write (const char * fname, int priv) 1861 1861 { 1862 1862 long status; … … 1870 1870 } 1871 1871 1872 SL_TICKET sl_open_read (c har * fname, int priv)1872 SL_TICKET sl_open_read (const char * fname, int priv) 1873 1873 { 1874 1874 long status; … … 1887 1887 } 1888 1888 1889 SL_TICKET sl_open_fastread (c har * fname, int priv)1889 SL_TICKET sl_open_fastread (const char * fname, int priv) 1890 1890 { 1891 1891 long status; … … 1899 1899 } 1900 1900 1901 SL_TICKET sl_open_rdwr (c har * fname, int priv)1901 SL_TICKET sl_open_rdwr (const char * fname, int priv) 1902 1902 { 1903 1903 long status; … … 1911 1911 } 1912 1912 1913 SL_TICKET sl_open_safe_rdwr (c har * fname, int priv)1913 SL_TICKET sl_open_safe_rdwr (const char * fname, int priv) 1914 1914 { 1915 1915 long status; … … 1923 1923 } 1924 1924 1925 SL_TICKET sl_open_write_trunc (c har * fname, int priv)1925 SL_TICKET sl_open_write_trunc (const char * fname, int priv) 1926 1926 { 1927 1927 long status; … … 1935 1935 } 1936 1936 1937 SL_TICKET sl_open_rdwr_trunc (c har * fname, int priv)1937 SL_TICKET sl_open_rdwr_trunc (const char * fname, int priv) 1938 1938 { 1939 1939 long status; … … 2490 2490 } 2491 2491 2492 2492 /* ---------------------------------------------------------------- 2493 * 2494 * Overflow tests 2495 * 2496 * ---------------------------------------------------------------- */ 2497 2498 int sl_ok_muli (int a, int b) /* a*b */ 2499 { 2500 if (a >= (INT_MIN / b) && a <= (INT_MAX / b)) 2501 return SL_TRUE; /* no overflow */ 2502 return SL_FALSE; 2503 } 2504 2505 int sl_ok_divi (int a, int b) /* a/b */ 2506 { 2507 (void) a; 2508 if (b != 0) 2509 return SL_TRUE; /* no overflow */ 2510 return SL_FALSE; 2511 } 2512 2513 int sl_ok_addi (int a, int b) /* a+b */ 2514 { 2515 if (a >= 0 && b >= 0) 2516 { 2517 if (a <= (INT_MAX - b)) 2518 return SL_TRUE; /* no overflow */ 2519 else 2520 return SL_FALSE; 2521 } 2522 else if (a < 0 && b < 0) 2523 { 2524 if (a >= (INT_MIN - b)) 2525 return SL_TRUE; /* no overflow */ 2526 else 2527 return SL_FALSE; 2528 } 2529 return SL_TRUE; 2530 } 2531 2532 int sl_ok_subi (int a, int b) /* a-b */ 2533 { 2534 if (a >= 0 && b < 0) 2535 { 2536 if (a <= (INT_MAX + b)) 2537 return SL_TRUE; /* no overflow */ 2538 else 2539 return SL_FALSE; 2540 } 2541 else if (a < 0 && b >= 0) 2542 { 2543 if (a >= (INT_MIN + b)) 2544 return SL_TRUE; /* no overflow */ 2545 else 2546 return SL_FALSE; 2547 } 2548 return SL_TRUE; 2549 }
Note:
See TracChangeset
for help on using the changeset viewer.