Skip to content

Commit

Permalink
Removing all calls to 'atoi' and using OpenBSD's 'strtonum' instead
Browse files Browse the repository at this point in the history
  • Loading branch information
fcambus committed Jan 20, 2016
1 parent 838d9bd commit 95fbe5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
4 changes: 4 additions & 0 deletions src/ansilove.h
Expand Up @@ -24,6 +24,10 @@
#include "filesize.h"
#include "sauce.h"

#ifndef HAVE_STRTONUM
#include "strtonum.h"
#endif

#ifndef ansilove_h
#define ansilove_h

Expand Down
18 changes: 10 additions & 8 deletions src/loaders/ansi.c
Expand Up @@ -23,6 +23,8 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
bool transparent = false;
bool workbench = false;

const char *errstr;

// font selection
alSelectFont(&fontData, font);

Expand Down Expand Up @@ -166,8 +168,8 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi

if (seqArrayCount > 1) {
// convert grabbed sequence content to integers
seq_line = atoi(seqArray[0]);
seq_column = atoi(seqArray[1]);
seq_line = strtonum(seqArray[0], 0, INT32_MAX, &errstr);
seq_column = strtonum(seqArray[1], 0, INT32_MAX, &errstr);

// finally set the positions
position_y = seq_line-1;
Expand All @@ -189,7 +191,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop);

// now get escape sequence's position value
int32_t seq_line = atoi(seqGrab);
int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr);

if (seq_line == 0) {
seq_line = 1;
Expand All @@ -208,7 +210,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop);

// now get escape sequence's position value
int32_t seq_line = atoi(seqGrab);
int32_t seq_line = strtonum(seqGrab, 0, INT32_MAX, &errstr);

if (seq_line == 0) {
seq_line = 1;
Expand All @@ -227,7 +229,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop);

// now get escape sequence's position value
int32_t seq_column = atoi(seqGrab);
int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr);

if (seq_column == 0) {
seq_column = 1;
Expand All @@ -251,7 +253,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop);

// now get escape sequence's content length
int32_t seq_column = atoi(seqGrab);
int32_t seq_column = strtonum(seqGrab, 0, INT32_MAX, &errstr);

if (seq_column == 0) {
seq_column = 1;
Expand Down Expand Up @@ -295,7 +297,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
seqGrab = substr((char *)input_file_buffer, loop+2, ansi_sequence_loop);

// convert grab to an integer
int32_t eraseDisplayInt = atoi(seqGrab);
int32_t eraseDisplayInt = strtonum(seqGrab, 0, INT32_MAX, &errstr);

if (eraseDisplayInt == 2)
{
Expand Down Expand Up @@ -327,7 +329,7 @@ void ansi(char *input, char *output, char *retinaout, char *font, int32_t int_bi
for (seq_graphics_loop = 0; seq_graphics_loop < seqArrayCount; seq_graphics_loop++)
{
// convert split content value to integer
seqValue = atoi(seqArray[seq_graphics_loop]);
seqValue = strtonum(seqArray[seq_graphics_loop], 0, INT32_MAX, &errstr);

if (seqValue == 0)
{
Expand Down

0 comments on commit 95fbe5e

Please sign in to comment.