FreeCalypso > hg > freecalypso-tools
view ffstools/tiffs-mkfs/ffsparam.c @ 965:2969032bdfac
fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing
The only 100% safe way to pass a NULL pointer as a function argument
in K&R C is to cast 0 to a pointer type; failing to do so may cause
mysterious bugs (invalid stack frames or garbage in argument registers)
on 64-bit machines. This issue has already been fixed in most of
FC host tools, but I just found some missed spots: passing of NULL UDH
to PDU encoding functions in fcup-smsend[mult] in the case of single
(not concatenated) SMS.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 01 Sep 2023 07:33:51 +0000 |
parents | 178ed445021d |
children |
line wrap: on
line source
#include <sys/types.h> #include <sys/param.h> #include <ctype.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include "struct.h" #include "globals.h" void parse_org_arg(arg) char *arg; { char *cp; cp = index(arg, 'x'); if (!cp || !isdigit(cp[1]) || !isdigit(arg[0])) { fprintf(stderr, "error: TIFFS organization argument \"%s\" is invalid\n", arg); exit(1); } *cp++ = '\0'; if (!strcmp(arg, "8")) ffs_sector_size = 0x2000; else if (!strcmp(arg, "16")) ffs_sector_size = 0x4000; else if (!strcmp(arg, "32")) ffs_sector_size = 0x8000; else if (!strcmp(arg, "64")) ffs_sector_size = 0x10000; else if (!strcmp(arg, "128")) ffs_sector_size = 0x20000; else if (!strcmp(arg, "256")) ffs_sector_size = 0x40000; else { fprintf(stderr, "error: \"%s\" is not a recognized flash sector size\n", arg); exit(1); } ffs_nsectors = atoi(cp); if (ffs_nsectors < 3 || ffs_nsectors > 128) { fprintf(stderr, "error: \"%s\" is not a reasonable number of FFS sectors\n", cp); exit(1); } } void preen_chunk_size_max() { if (chunk_size_max) { if (chunk_size_max > ffs_sector_size / 2) { fprintf(stderr, "error: max chunk size specified with -c is too large\n"); exit(1); } return; } /* default matching TI's code */ if (ffs_sector_size * ffs_nsectors > 1024*1024) chunk_size_max = 8192; else if (ffs_sector_size / 8 < 2048) chunk_size_max = ffs_sector_size / 8; else chunk_size_max = 2048; } void preen_journal_size() { if (journal_size) return; /* default matching TI's code */ journal_size = ffs_sector_size >> 4; if (journal_size < 1024) journal_size = 1024; } void preen_block_files_max() { unsigned local_journal_size; if (block_files_max) return; /* default matching TI's code */ local_journal_size = ffs_sector_size >> 4; if (local_journal_size < 1024) local_journal_size = 1024; block_files_max = (local_journal_size >> 4) - 6; }