Skip to content

Commit

Permalink
统一字符串有效性判断
Browse files Browse the repository at this point in the history
  • Loading branch information
mutouyun committed Sep 24, 2023
1 parent 6f31180 commit f52b125
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/libipc/platform/posix/shm_posix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ namespace ipc {
namespace shm {

id_t acquire(char const * name, std::size_t size, unsigned mode) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail acquire: name is empty\n");
return nullptr;
}
Expand Down Expand Up @@ -185,7 +185,7 @@ void remove(id_t id) {
}

void remove(char const * name) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail remove: name is empty\n");
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/libipc/platform/win/shm_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace ipc {
namespace shm {

id_t acquire(char const * name, std::size_t size, unsigned mode) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail acquire: name is empty\n");
return nullptr;
}
Expand Down Expand Up @@ -124,7 +124,7 @@ void remove(id_t id) {
}

void remove(char const * name) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail remove: name is empty\n");
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/libipc/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "libipc/utility/log.h"
#include "libipc/platform/detail.h"
#include "libipc/circ/elem_def.h"
#include "libipc/memory/resource.h"

namespace ipc {
namespace detail {
Expand All @@ -29,7 +30,7 @@ class queue_conn {

template <typename Elems>
Elems* open(char const * name) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail open waiter: name is empty!\n");
return nullptr;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libipc/shm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void handle::sub_ref() noexcept {
}

bool handle::acquire(char const * name, std::size_t size, unsigned mode) {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail acquire: name is empty\n");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libipc/sync/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool condition::valid() const noexcept {
}

bool condition::open(char const *name) noexcept {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail condition open: name is empty\n");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libipc/sync/mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ bool mutex::valid() const noexcept {
}

bool mutex::open(char const *name) noexcept {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail mutex open: name is empty\n");
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/libipc/sync/semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ bool semaphore::valid() const noexcept {
}

bool semaphore::open(char const *name, std::uint32_t count) noexcept {
if (name == nullptr || name[0] == '\0') {
if (!is_valid_string(name)) {
ipc::error("fail semaphore open: name is empty\n");
return false;
}
Expand Down

0 comments on commit f52b125

Please sign in to comment.