Rizin
unix-like reverse engineering framework and cli tools
regerror.c File Reference
#include <sys/types.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <limits.h>
#include <stdlib.h>
#include "rz_regex.h"
#include "utils.h"

Go to the source code of this file.

Classes

struct  rerr
 

Functions

static char * regatoi (const RzRegex *, char *, int)
 
RZ_API size_t rz_regex_error (int errcode, const RzRegex *preg, char *errbuf, size_t errbuf_size)
 

Variables

static struct rerr rerrs []
 

Function Documentation

◆ regatoi()

static char * regatoi ( const RzRegex preg,
char *  localbuf,
int  localbufsize 
)
static

Definition at line 118 of file regerror.c.

118  {
119  struct rerr *r;
120 
121  for (r = rerrs; r->code != 0; r++) {
122  if (strcmp(r->name, preg->re_endp) == 0) {
123  break;
124  }
125  }
126  if (r->code == 0) {
127  return ("0");
128  }
129 
130  (void)snprintf(localbuf, localbufsize, "%d", r->code);
131  return (localbuf);
132 }
#define r
Definition: crypto_rc6.c:12
snprintf
Definition: kernel.h:364
static struct rerr rerrs[]
Definition: regerror.c:49
const char * re_endp
Definition: rz_regex.h:11

References r, rz_regex_t::re_endp, rerrs, and snprintf.

Referenced by rz_regex_error().

◆ rz_regex_error()

RZ_API size_t rz_regex_error ( int  errcode,
const RzRegex preg,
char *  errbuf,
size_t  errbuf_size 
)

Definition at line 78 of file regerror.c.

78  {
79  struct rerr *r;
80  size_t len;
81  int target = errcode & ~RZ_REGEX_ITOA;
82  char *s;
83  char convbuf[50];
84 
85  if (errcode == RZ_REGEX_ATOI) {
86  s = regatoi(preg, convbuf, sizeof convbuf);
87  } else {
88  for (r = rerrs; r->code != 0; r++) {
89  if (r->code == target) {
90  break;
91  }
92  }
93 
94  if (errcode & RZ_REGEX_ITOA) {
95  if (r->code != 0) {
96  STRLCPY(convbuf, r->name, sizeof(convbuf) - 1);
97  } else {
98  snprintf(convbuf, sizeof convbuf, "RZ_REGEX_0x%x", target);
99  }
100  s = convbuf;
101  } else {
102  s = r->explain;
103  }
104  }
105 
106  len = strlen(s) + 1;
107  if (errbuf_size > 0) {
108  STRLCPY(errbuf, s, errbuf_size - 1);
109  }
110 
111  return len;
112 }
size_t len
Definition: 6502dis.c:15
#define STRLCPY(x, y, z)
Definition: utils.h:44
static char * regatoi(const RzRegex *, char *, int)
Definition: regerror.c:118
static RzSocket * s
Definition: rtr.c:28
#define RZ_REGEX_ITOA
Definition: rz_regex.h:51
#define RZ_REGEX_ATOI
Definition: rz_regex.h:50

References len, r, regatoi(), rerrs, RZ_REGEX_ATOI, RZ_REGEX_ITOA, s, snprintf, and STRLCPY.

Referenced by check_fmt(), and magiccheck().

Variable Documentation

◆ rerrs

struct rerr rerrs[]
static
Initial value:
= {
{ RZ_REGEX_NOMATCH, "RZ_REGEX_NOMATCH", "regexec() failed to match" },
{ RZ_REGEX_BADPAT, "RZ_REGEX_BADPAT", "invalid regular expression" },
{ RZ_REGEX_ECOLLATE, "RZ_REGEX_ECOLLATE", "invalid collating element" },
{ RZ_REGEX_ECTYPE, "RZ_REGEX_ECTYPE", "invalid character class" },
{ RZ_REGEX_EESCAPE, "RZ_REGEX_EESCAPE", "trailing backslash (\\)" },
{ RZ_REGEX_ESUBREG, "RZ_REGEX_ESUBREG", "invalid backreference number" },
{ RZ_REGEX_EBRACK, "RZ_REGEX_EBRACK", "brackets ([ ]) not balanced" },
{ RZ_REGEX_EPAREN, "RZ_REGEX_EPAREN", "parentheses not balanced" },
{ RZ_REGEX_EBRACE, "RZ_REGEX_EBRACE", "braces not balanced" },
{ RZ_REGEX_BADBR, "RZ_REGEX_BADBR", "invalid repetition count(s)" },
{ RZ_REGEX_ERANGE, "RZ_REGEX_ERANGE", "invalid character range" },
{ RZ_REGEX_ESPACE, "RZ_REGEX_ESPACE", "out of memory" },
{ RZ_REGEX_BADRPT, "RZ_REGEX_BADRPT", "repetition-operator operand invalid" },
{ RZ_REGEX_EMPTY, "RZ_REGEX_EMPTY", "empty (sub)expression" },
{ RZ_REGEX_ASSERT, "RZ_REGEX_ASSERT", "\"can't happen\" -- you found a bug" },
{ RZ_REGEX_INVARG, "RZ_REGEX_INVARG", "invalid argument to regex routine" },
{ 0, "", "*** unknown regexp error code ***" }
}
#define RZ_REGEX_ESPACE
Definition: rz_regex.h:44
#define RZ_REGEX_BADPAT
Definition: rz_regex.h:34
#define RZ_REGEX_BADBR
Definition: rz_regex.h:42
#define RZ_REGEX_ECTYPE
Definition: rz_regex.h:36
#define RZ_REGEX_EBRACK
Definition: rz_regex.h:39
#define RZ_REGEX_ECOLLATE
Definition: rz_regex.h:35
#define RZ_REGEX_ERANGE
Definition: rz_regex.h:43
#define RZ_REGEX_ESUBREG
Definition: rz_regex.h:38
#define RZ_REGEX_EBRACE
Definition: rz_regex.h:41
#define RZ_REGEX_EMPTY
Definition: rz_regex.h:46
#define RZ_REGEX_BADRPT
Definition: rz_regex.h:45
#define RZ_REGEX_NOMATCH
Definition: rz_regex.h:33
#define RZ_REGEX_INVARG
Definition: rz_regex.h:48
#define RZ_REGEX_EPAREN
Definition: rz_regex.h:40
#define RZ_REGEX_EESCAPE
Definition: rz_regex.h:37
#define RZ_REGEX_ASSERT
Definition: rz_regex.h:47

Referenced by regatoi(), and rz_regex_error().