Skip to content

Commit

Permalink
used VALIDATE_ARG_NOT_NULL_INT_RETURN in functions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ankaa19 authored Dec 4, 2024
1 parent d4bd06f commit 9921e8f
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions src/facility.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <string.h>
#include <stumpless/facility.h>
#include "private/facility.h"
#include <private/validate.h>
#include "private/strhelper.h"
#include "private/error.h"

Expand All @@ -39,23 +40,18 @@ stumpless_get_facility_string( enum stumpless_facility facility ) {

enum stumpless_facility
stumpless_get_facility_enum( const char *facility_string ) {
if (!facility_string) {
raise_argument_empty( "facility_string is NULL" );
return -1;
}
VALIDATE_ARG_NOT_NULL_INT_RETURN(facility_string);

enum stumpless_facility facility = stumpless_get_facility_enum_from_buffer(facility_string, strlen(facility_string));
if (facility == -1) {
raise_invalid_facility(-1);
raise_invalid_facility(STUMPLESS_INVALID_ENCODING);
}
return facility;
}

enum stumpless_facility
stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t facility_buffer_length) {
if (!facility_buffer) {
raise_argument_empty( "facility_buffer is NULL" );
return -1;
}
VALIDATE_ARG_NOT_NULL_INT_RETURN(facility_buffer);

size_t facility_bound;
size_t i;
Expand All @@ -79,7 +75,7 @@ stumpless_get_facility_enum_from_buffer(const char *facility_buffer, size_t faci
if( strncasecmp_custom( facility_buffer, "AUTHPRIV", facility_buffer_length ) == 0 ) {
return STUMPLESS_FACILITY_AUTH2_VALUE;
}
raise_invalid_facility(-1);
raise_invalid_facility(STUMPLESS_INVALID_FACILITY);
return -1;
}

Expand All @@ -93,4 +89,4 @@ get_facility( int prival ) {
int
facility_is_invalid( int facility ) {
return facility < 0 || facility > ( 23 << 3 ) || facility % 8 != 0;
}
}

0 comments on commit 9921e8f

Please sign in to comment.