static void init(VMPM *vmpm) { unsigned int i; if ((vmpm->token_hash = malloc(HASH_SIZE * sizeof(Token))) == NULL) memory_error(NULL, MEMORY_ERROR); if ((vmpm->token = calloc(vmpm->I + 1, sizeof(Token **))) == NULL) memory_error(NULL, MEMORY_ERROR); if ((vmpm->token_index = calloc(vmpm->I + 1, sizeof(unsigned int))) == NULL) memory_error(NULL, MEMORY_ERROR); if ((vmpm->newtoken = malloc((vmpm->I + 1) * sizeof(Token_value))) == NULL) memory_error(NULL, MEMORY_ERROR); for (i = 1; i <= vmpm->I; i++) vmpm->newtoken[i] = 1; }
extern int init_queues(void) { bid_queueBatches = NewQueue(); bid_queueTapes = NewQueue(); bid_queueTapesDone = NewQueue(); bid_queueDevices = NewQueue(); bid_queueDevicesLocked = NewQueue(); bid_queueFiles = NewQueue(); bid_queueFilesProcessed = NewQueue(); bid_queueFilesDone = NewQueue(); if ( (NULL == bid_queueBatches) || (NULL == bid_queueTapes) || (NULL == bid_queueTapesDone) || (NULL == bid_queueDevices) || (NULL == bid_queueDevicesLocked) || (NULL == bid_queueFiles) || (NULL == bid_queueFilesProcessed) || (NULL == bid_queueFilesDone)) { memory_error("init_queues", "NewQueue", errno, dbproc); return(F_MEM_ERROR); } return(SUCCESS); }
int jsonrpc_notification(struct sip_msg* _m, char* _method, char* _params) { str method; str params; if (fixup_get_svalue(_m, (gparam_p)_method, &method) != 0) { LM_ERR("cannot get method value\n"); return -1; } if (fixup_get_svalue(_m, (gparam_p)_params, ¶ms) != 0) { LM_ERR("cannot get params value\n"); return -1; } struct jsonrpc_pipe_cmd *cmd; if (!(cmd = (struct jsonrpc_pipe_cmd *) shm_malloc(sizeof(struct jsonrpc_pipe_cmd)))) return memory_error(); memset(cmd, 0, sizeof(struct jsonrpc_pipe_cmd)); cmd->method = shm_strdup(&method); cmd->params = shm_strdup(¶ms); cmd->notify_only = 1; if (write(cmd_pipe, &cmd, sizeof(cmd)) != sizeof(cmd)) { LM_ERR("failed to write to io pipe: %s\n", strerror(errno)); return -1; } return 1; }
/* Read a line from standard input and put it in a char[] */ static char *readline(char *prompt) { size_t buf_len = 16; char *buf = xmalloc(buf_len * sizeof(char)); printf(prompt); if (fgets(buf, buf_len, stdin) == NULL) { free(buf); return NULL; } do { size_t l = strlen(buf); if ((l > 0) && (buf[l - 1] == '\n')) { l--; buf[l] = 0; return buf; } if (buf_len >= (INT_MAX / 2)) { exit(memory_error()); } buf_len *= 2; buf = xrealloc(buf, buf_len * sizeof(char)); if (fgets(buf + l, buf_len - l, stdin) == NULL) { return buf; } } while (1); }
void stream_on_alloc(uv_handle_t* client, size_t suggested_size, uv_buf_t* buf) { char* buffer; if(!(buffer = malloc(suggested_size))){ memory_error("Unable to allocate buffer of size %d", suggested_size); } *buf = uv_buf_init(buffer, suggested_size); }
/* Return a pointer to a string containing the array size */ char *parse_array_size (char string[]) { char output_buffer[BUFFER_LEN]; int length; char *size_string, *ptr = string; memset (output_buffer, '\0', BUFFER_LEN); ptr = find_char (ptr, '('); while (ptr < find_char(string,')')) { if (strlen(output_buffer) != 0) strcat (output_buffer, "*"); length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1; strcat (output_buffer, "("); if (find_char(ptr,':')-ptr < length) { strcat (output_buffer, "1-"); strncat (output_buffer, ptr, find_char(ptr,':')-ptr-1); strcat (output_buffer, "+"); ptr = find_char (ptr, ':'); length = min (find_char(ptr,',')-ptr, find_char(ptr,')')-ptr) - 1; } strncat (output_buffer, ptr, length); strcat (output_buffer, ")"); ptr = skip_blanks (find_char (ptr, ',')); } size_string = malloc (strlen(output_buffer)+1); if (size_string == NULL) memory_error (); strcpy (size_string, output_buffer); return (size_string); }
void enter(struct node **node, char *word) { int result; char *save_string(char *); if ((*node) == NULL) { (*node) = malloc(sizeof(struct node)); if ((*node) == NULL) memory_error(); (*node)->left = NULL; (*node)->right = NULL; (*node)->word = save_string(word); return; } result = strcmp((*node)->word, word); if (result == 0) return; if (result < 0) enter(&(*node)->right, word); else enter(&(*node)->left, word); }
/* This routine is called with the argument to each -D command-line option. ** Add the macro defined to the azDefine array. */ static void handle_D_option(char *z){ char **paz; nDefine++; azDefine = realloc(azDefine, sizeof(azDefine[0])*nDefine); if( azDefine==0 ){ memory_error(); } paz = &azDefine[nDefine-1]; *paz = malloc( strlen(z)+1 ); if( *paz==0 ){ memory_error(); } strcpy(*paz, z); for(z=*paz; *z && *z!='='; z++){} *z = 0; }
int main(int argc, char *argv[]) { if (argc != 4) invocation_error(argv[0], "[input file 1] [input file 2] [output file]"); char *output_filename = argv[3]; struct stat file1_stat, file2_stat; FileInfo larger, smaller; off_t record_size = (off_t)get_part_record_size(); validate_input_file(argv[1], &file1_stat, record_size); validate_input_file(argv[2], &file2_stat, record_size); sort_input_files(argv[1], &file1_stat, argv[2], &file2_stat, &larger, &smaller, record_size); Part out_buffer = (Part)malloc(larger.size + smaller.size); if (!out_buffer) memory_error(__FILE__, __LINE__, __func__); if (read_input(&larger, out_buffer, record_size) != 0) { free(out_buffer); exit(EXIT_FAILURE); } Part in_buffer = malloc(smaller.size); if (!in_buffer) { free(out_buffer); memory_error(__FILE__, __LINE__, __func__); } if (read_input(&smaller, in_buffer, record_size) != 0) { free(in_buffer); free(out_buffer); exit(EXIT_FAILURE); } size_t out_count = merge_buffers(in_buffer, smaller.count, out_buffer, larger.count); free(in_buffer); if (write_output(output_filename, out_buffer, out_count, record_size) != 0) { free(out_buffer); exit(EXIT_FAILURE); } free(out_buffer); return 0; }
/* Add a variable to a linked list */ void create (struct node *start, int vartype, char string[], char comment[]) { struct node *end = start, *temp; if (find_node (start, string) == NULL) { /* Create a new node and add it to the end of the linked list */ while (end->next != NULL) end = end->next; end->next = malloc (sizeof(struct node)); if (end->next == NULL) memory_error (); end = end->next; end->vartype = vartype; end->action = NOP; end->calltype = current_calltype; end->line_number = current_line; end->name = calloc (extract_text(string)+1, sizeof(char)); if (end->name == NULL) memory_error (); copy (end->name, string, extract_text(string)); if ((find_char (string, '(') < find_char (string, ',')) && (find_char (string, '(') < find_char (string, '!'))) { /* Variable is an array */ if (start == common_start) { /* Array is defined in a common block, so print a warning */ eprint_newline (); eprint ("Warning - Array size defined in common block:"); eprint_newline (); eprint_line (current_line); eprintn (string, find_char(string, ')') - string); eprint_newline (); temp = find_node (register_start, string); if (temp != NULL) { if (temp->vartype > 0) array_flags[temp->calltype][temp->vartype]=1; free (temp->size); temp->size = parse_array_size (string); end->size = NULL; } } else end->size = parse_array_size (string); } else (end->size = NULL); if (comment != NULL) { end->title = calloc (strlen(comment), sizeof(char)); if (end->title == NULL) memory_error (); copy (end->title, comment, strlen(comment)-1); } else end->title = NULL; end->next = NULL; } }
/* Same as target_read_memory, but report an error if can't read. */ void read_memory (CORE_ADDR memaddr, gdb_byte *myaddr, int len) { int status; status = target_read_memory (memaddr, myaddr, len); if (status != 0) memory_error (status, memaddr); }
static void *xrealloc(void *ptr, size_t size) { void *p = realloc(ptr, size); if (!p) { exit(memory_error()); } return p; }
static void *xmalloc(size_t size) { void *p = malloc(size); if (!p) { exit(memory_error()); } return p; }
char *save_w(char *string) // copy string to heap { char *new_string; new_string = malloc((unsigned) (strlen(string)+1)); if (new_string == NULL) memory_error(); strcpy(new_string,string); return (new_string); }
/* This function calls calloc(). */ void * debug_calloc(size_t nelem, size_t elsize, const char *file, int line) { void *mptr; size_t nbytes; int mid = id_counter; nbytes = nelem*elsize; /*LINTED*/ if ((int)nbytes <= 0) memory_error((void *) NULL, "debug_calloc", mid, file, line, file, line); /* LINTED */ mptr = calloc(rbytes_(nbytes),1); if (mptr == NULL) memory_error((void *) NULL, "debug_calloc", mid, file, line, file, line); setup_space_and_issue_warrant(mptr, nbytes, file, line); return malloc2user_(mptr); }
int memory_deletefile(char *adresse) { FONTCHARACTER *adr = memory_char2font(adresse); int i = Bfile_DeleteFile(adr); if(i<0) memory_error("deletefil.()","DeleteFil.()",i); free(adr); return i; }
int memory_openfile(char *adresse, int mode) { FONTCHARACTER *adr = memory_char2font(adresse); int i = Bfile_OpenFile(adr,mode); if(i<0) memory_error("openfile()","OpenFile()",i); free(adr); return i; }
int memory_createdir(char *adresse) { FONTCHARACTER *adr = memory_char2font(adresse); int i = Bfile_CreateDirectory(adr); if(i<0) memory_error("createdir()","CreateDir.()",i); free(adr); return 1; }
int memory_createfile(char *adresse, int size) { FONTCHARACTER *adr = memory_char2font(adresse); int i = Bfile_CreateFile(adr,size); if(i<0) memory_error("createfile()","CreateFile()",i); free(adr); return i; }
int memory_save(char *adresse, void *data, int l) { FONTCHARACTER *adr = memory_char2font(adresse); int x=0, handle; if(memory_exists(adresse)) x = Bfile_DeleteFile(adr); if(x<0) { memory_error("save()","DeleteFile()",x); free(adr); return x; } x = Bfile_CreateFile(adr,l+1); if(x<0) { memory_error("save()","CreateFile()",x); free(adr); return x; } handle = Bfile_OpenFile(adr,0x02); if(handle<0) { memory_error("save()","OpenFile()",handle); free(adr); return handle; } x = memory_writefile(handle,data,l); if(x<0) { memory_error("save()","WriteFile()",x); free(adr); return x; } memory_closefile(handle); free(adr); return 0; }
static STK_ELT *new_element() { STK_ELT *new_elt; if ((new_elt = (STK_ELT *) gen_alloc(sizeof(STK_ELT),"new_element")) == NULL) memory_error(); return(new_elt); }
char *save_string(char *string) { char *new_string; new_string = malloc((unsigned) (strlen(string) + 1)); if (new_string == NULL) { memory_error(); } strcpy(new_string, string); return new_string; }
static Node *create_node(Part p) { Node *new_node = malloc(sizeof(Node)); if (!new_node) memory_error(__FILE__, __LINE__, __func__); new_node->part = p; new_node->next = NULL; return new_node; }
struct node* memory_allocate_node() { struct node *new_node; new_node = (struct node*)malloc(sizeof(struct node)); if(new_node == NULL) memory_error(); return new_node; }
/* * allocates memory for a string * * params: * char* word - string to be allocated memory * returns: * char* - copy of string with memory allocated */ char* memory_allocate_string(char * word) { char *new_word; new_word = (char*)malloc((unsigned)(strlen(word) + 1 )); if(new_word == NULL) memory_error(); strcpy(new_word, word); return (new_word); }
/* Same as target_write_memory, but report an error if cannot write: */ void write_memory(CORE_ADDR memaddr, const bfd_byte *myaddr, int len) { int status; bfd_byte *bytes = (bfd_byte *)alloca(len); memcpy(bytes, myaddr, len); status = target_write_memory(memaddr, bytes, len); if (status != 0) memory_error(status, memaddr); }
static void parse_ref_list(ref_list *ref_list_ptr) { start_parsing_value(); ref_list_ptr->delete_ref_list(); do { int ref_no = parse_integer_in_value(); if (!ref_list_ptr->add_ref(ref_no)) memory_error("reference"); } while (token_in_value_is(",")); stop_parsing_value(); }
/* This function calls malloc(). */ void * debug_malloc(size_t nbytes, const char *file, int line) { void *mptr; void *uptr; int mid = id_counter; /*LINTED*/ if ((int)nbytes <= 0) memory_error((void *) NULL, "debug_malloc", mid, file, line, file, line); /* LINTED */ mptr = malloc(rbytes_(nbytes)); if (mptr == NULL) memory_error((void *) NULL, "debug_malloc", mid, file, line, file, line); setup_space_and_issue_warrant(mptr, nbytes, file, line); uptr = malloc2user_(mptr); #ifdef ALLOC_CHAR (void)memset(uptr, ALLOC_CHAR, (size_t)nbytes); #endif return uptr; }
void *memory_load(char *adresse) { FONTCHARACTER *adr = memory_char2font(adresse); int handle, x, size; void *p; if((handle=Bfile_OpenFile(adr,_OPENMODE_READ))<0) { memory_error("load()","OpenFile()",handle); return NULL; } size = Bfile_GetFileSize(handle)+1; p = calloc(size,1); if(!p) { memory_error("load()","malloc()",1); Bfile_CloseFile(handle); free(adr); return NULL; } if((x=Bfile_ReadFile(handle,p,size,0))<0) { memory_error("load()","ReadFile()",x); Bfile_CloseFile(handle); free(adr); return NULL; } Bfile_CloseFile(handle); free(adr); return p; }
/* ---------- code */ void initialize_keyboard_controller( void) { ActionQueue *queue; short player_index; // vassert(NUMBER_OF_KEYS == NUMBER_OF_STANDARD_KEY_DEFINITIONS, // csprintf(temporary, "NUMBER_OF_KEYS == %d, NUMBER_OF_KEY_DEFS = %d. Not Equal!", NUMBER_OF_KEYS, NUMBER_OF_STANDARD_KEY_DEFINITIONS)); assert(NUMBER_OF_STANDARD_KEY_DEFINITIONS==NUMBER_OF_LEFT_HANDED_KEY_DEFINITIONS); assert(NUMBER_OF_LEFT_HANDED_KEY_DEFINITIONS==NUMBER_OF_POWERBOOK_KEY_DEFINITIONS); // get globals initialized heartbeat_count= 0; input_task_active= FALSE; memset(&replay, 0, sizeof(struct replay_private_data)); input_task= install_timer_task(TICKS_PER_SECOND, input_controller); assert(input_task); atexit(remove_input_controller); set_keys_to_match_preferences(); /* Allocate the recording queues */ replay.recording_queues = (ActionQueue *) malloc(MAXIMUM_NUMBER_OF_PLAYERS * sizeof(ActionQueue)); assert(replay.recording_queues); if(!replay.recording_queues) alert_user(fatalError, strERRORS, outOfMemory, memory_error()); /* Allocate the individual ones */ for (player_index= 0; player_index<MAXIMUM_NUMBER_OF_PLAYERS; player_index++) { queue= get_player_recording_queue(player_index); queue->read_index= queue->write_index = 0; queue->buffer= (long *) malloc(MAXIMUM_QUEUE_SIZE*sizeof(long)); if(!queue->buffer) alert_user(fatalError, strERRORS, outOfMemory, memory_error()); } enter_mouse(0); return; }