⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 arg_check.c

📁 测试内存泄露工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * Functions for testing of string routines arguments. * * Copyright 2000 by Gray Watson * * This file is part of the dmalloc package. * * Permission to use, copy, modify, and distribute this software for * any purpose and without fee is hereby granted, provided that the * above copyright notice and this permission notice appear in all * copies, and that the name of Gray Watson not be used in advertising * or publicity pertaining to distribution of the document or software * without specific, written prior permission. * * Gray Watson makes no representations about the suitability of the * software described herein for any purpose.  It is provided "as is" * without express or implied warranty. * * The author may be contacted via http://dmalloc.com/ * * $Id: arg_check.c,v 1.35 2004/01/31 16:19:34 gray Exp $ *//* * This file contains functions to be used to verify the arguments of * string functions.   If enabled these can discover problems with * heap-based strings (such as fence errors) much closer to the error. */#define DMALLOC_DISABLE#if HAVE_STRING_H# include <string.h>#endif#if HAVE_STDLIB_H# include <stdlib.h>#endif#include "dmalloc.h"#include "conf.h"#include "chunk.h"#include "debug_tok.h"#include "error.h"#include "dmalloc_loc.h"#include "arg_check.h"#if HAVE_ATOI/* * Dummy function for checking atoi's arguments. */int	_dmalloc_atoi(const char *str){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "atoi", str,			     0 /* not exact */, -1)) {      dmalloc_message("bad pointer argument found in atoi");    }  }  return atoi(str);}#endif /* HAVE_ATOI */#if HAVE_ATOL/* * Dummy function for checking atol's arguments. */long	_dmalloc_atol(const char *str){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "atol", str,			     0 /* not exact */, -1)) {      dmalloc_message("bad pointer argument found in atol");    }  }  return atol(str);}#endif /* HAVE_ATOL */#if HAVE_BCMP/* * Dummy function for checking bcmp's arguments. */int	_dmalloc_bcmp(const void *b1, const void *b2, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "bcmp", b1,			      0 /* not exact */, len))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "bcmp", b2,				 0 /* not exact */, len))) {      dmalloc_message("bad pointer argument found in bcmp");    }  }  return bcmp(b1, b2, len);}#endif /* HAVE_BCMP */#if HAVE_BCOPY/* * Dummy function for checking bcopy's arguments. */void	_dmalloc_bcopy(const void *from, void *to, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "bcopy", from,			      0 /* not exact */, len))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "bcopy", to,				 0 /* not exact */, len))) {      dmalloc_message("bad pointer argument found in bcopy");    }  }  bcopy(from, to, len);}#endif /* HAVE_BCOPY */#if HAVE_BZERO/* * Dummy function for checking bzero's arguments. */void	_dmalloc_bzero(void *buf, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "bzero", buf,			     0 /* not exact */, len)) {      dmalloc_message("bad pointer argument found in bzero");    }  }  bzero(buf, len);}#endif /* HAVE_BZERO */#if HAVE_INDEX/* * Dummy function for checking index's arguments. */char	*_dmalloc_index(const char *str, const char ch){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "index", str,			     0 /* not exact */, -1)) {      dmalloc_message("bad pointer argument found in index");    }  }  return (char *)index(str, ch);}#endif /* HAVE_INDEX */#if HAVE_MEMCCPY/* * Dummy function for checking memccpy's arguments. */void	*_dmalloc_memccpy(void *s1, const void *s2, const int ch,			  const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    /* maybe len maybe first ch */    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "memccpy", s1,			      0 /* not exact */, 0))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "memccpy", s2,				 0 /* not exact */, 0))) {      dmalloc_message("bad pointer argument found in memccpy");    }  }  return (void *)memccpy(s1, s2, ch, len);}#endif /* HAVE_MEMCCPY */#if HAVE_MEMCHR/* * Dummy function for checking memchr's arguments. */void	*_dmalloc_memchr(const void *s1, const int ch, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "memchr", s1,			     0 /* not exact */, len)) {      dmalloc_message("bad pointer argument found in memchr");    }  }  return (void *)memchr(s1, ch, len);}#endif /* HAVE_MEMCHR */#if HAVE_MEMCMP/* * Dummy function for checking memcmp's arguments. */int	_dmalloc_memcmp(const void *b1, const void *b2, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "memcmp", b1,			      0 /* not exact */, len))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "memcmp", b2,				 0 /* not exact */, len))) {      dmalloc_message("bad pointer argument found in memcmp");    }  }  return memcmp(b1, b2, len);}#endif /* HAVE_MEMCMP */#if HAVE_MEMCPY/* * Dummy function for checking memcpy's arguments. */void	*_dmalloc_memcpy(void *to, const void *from, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "memcpy", to,			      0 /* not exact */, len))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "memcpy", from,				 0 /* not exact */, len))) {      dmalloc_message("bad pointer argument found in memcpy");    }  }  return (void *)memcpy(to, from, len);}#endif /* HAVE_MEMCPY */#if HAVE_MEMMOVE/* * Dummy function for checking memcpy's arguments. */void	*_dmalloc_memmove(void *to, const void *from, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "memmove", to,			      0 /* not exact */, len))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "memmove", from,				 0 /* not exact */, len))) {      dmalloc_message("bad pointer argument found in memmove");    }  }  return (void *)memmove(to, from, len);}#endif /* HAVE_MEMMOVE */#if HAVE_MEMSET/* * Dummy function for checking memset's arguments. */void	*_dmalloc_memset(void *buf, const int ch, const DMALLOC_SIZE len){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "memset", buf,			     0 /* not exact */, len)) {      dmalloc_message("bad pointer argument found in memset");    }  }  return (void *)memset(buf, ch, len);}#endif /* HAVE_MEMSET */#if HAVE_RINDEX/* * Dummy function for checking rindex's arguments. */char	*_dmalloc_rindex(const char *str, const char ch){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if (! dmalloc_verify_pnt(__FILE__, __LINE__, "rindex", str,			     0 /* not exact */, -1)) {      dmalloc_message("bad pointer argument found in rindex");    }  }  return (char *)rindex(str, ch);}#endif /* HAVE_RINDEX */#if HAVE_STRCASECMP/* * Dummy function for checking strcasecmp's arguments. */int	_dmalloc_strcasecmp(const char *s1, const char *s2){  if (BIT_IS_SET(_dmalloc_flags, DEBUG_CHECK_FUNCS)) {    if ((! dmalloc_verify_pnt(__FILE__, __LINE__, "strcasecmp", s1,			      0 /* not exact */, -1))	|| (! dmalloc_verify_pnt(__FILE__, __LINE__, "strcasecmp", s2,				 0 /* not exact */, -1))) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -