我正在编写一个执行一些身份验证操作的函数.我有一个文件,所有的user_id:password:flag夫妻结构如下:
Users.txt
user_123:a1b2:0 user_124:a2b1:1 user_125:a2b2:2
这是代码:
int main(){
/*...*/
/*user_id, password retrieving*/
USRPSW* p = malloc(sizeof(USRPSW));
if(p == NULL){
fprintf(stderr, "Dynamic alloc error\n");
exit(EXIT_FAILURE);
}
memset((void*)p, 0, sizeof(USRPSW));
if(usr_psw_read(acc_sock_ds, p->user_id, USR_SIZE) <= 0){
printf("Failed read: connection with %s aborted.\n",
inet_ntoa(client_addr.sin_addr));
close(acc_sock_ds);
continue;
}
if(usr_psw_read(acc_sock_ds, p->password, PSW_SIZE) <= 0){
printf("Failed read: connection with %s aborted.\n",
inet_ntoa(client_addr.sin_addr));
close(acc_sock_ds);
continue;
}
/*Authentication through user_id, password*/
FILE *fd;
fd = fopen(USERSFILE, "r");
if(fd == NULL){
fprintf(stderr, "Users file opening error\n");
exit(EXIT_FAILURE);
} …Run Code Online (Sandbox Code Playgroud) 这个:
testl %esi, %esi
jle .L3
movl %esi, %eax
Run Code Online (Sandbox Code Playgroud)
如果testl对esi结果的逻辑AND 不能永远不会少但只有等于,则if esi为0.这样movl就无法达到.这是真的,或者我错过了一些事情.
第二步:
f1:
pushq %rbp
movq %rsp, %rbp
testl %esi, %esi
jle .L3
movl %esi, %eax
.L2:
incb (%rdi)
incq %rdi
decq %rax
jne .L2
.L3:
popq %rbp
ret
Run Code Online (Sandbox Code Playgroud)
在假设的C转换中,如果.L3由popthen ret和分支组成,则可以确定函数返回的值吗?
我正在努力尝试在类型的控制器过滤器属性中注入服务的ASP.NET MVC 6(beta 4版本)AuthorizationFilterAttribute.
这是服务(它注入了另一项服务)
public class UsersTableRepository
{
private readonly NeurosgarContext _dbContext;
public UsersTableRepository(NeurosgarContext DbContext)
{
_dbContext = DbContext;
}
public ICollection<User> AllUsers
{
get
{
return _dbContext.Users.ToList();
}
}
//other stuff...
}
Run Code Online (Sandbox Code Playgroud)
这是启动服务启用类中的ConfigureServices方法
public void ConfigureServices(IServiceCollection services)
{
//...
services.AddSingleton<NeurosgarContext>(a => NeurosgarContextFactory.GetContext());
services.AddSingleton<UifTableRepository<Nazione>>();
services.AddSingleton<UsersTableRepository>();
}
Run Code Online (Sandbox Code Playgroud)
一个简单的"虚拟"控制器,上面定义了两个过滤器.您可以注意到我已经通过装饰属性在该控制器中完成了DI [FromServices]并且它可以工作.
[Route("[controller]")]
[BasicAuthenticationFilter(Order = 0)]
[BasicAuthorizationFilter("Admin", Order = 1)]
public class DummyController : Controller
{
[FromServices]
public UsersTableRepository UsersRepository { get; set; }
// GET: /<controller>/
[Route("[action]")]
public IActionResult …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此代码的一些问题:
#include <stdio.h>
#include <stdlib.h>
#define SIZE 30
#define Error_(x) { perror(x); exit(1); }
int main(int argc, char *argv[]) {
char message[SIZE];
int pid, status, ret, fd[2];
ret = pipe(fd);
if(ret == -1) Error_("Pipe creation");
if((pid = fork()) == -1) Error_("Fork error");
if(pid == 0){ //child process: reader (child wants to receive data from the parent)
close(fd[1]); //reader closes unused ch.
while( read(fd[0], message, SIZE) > 0 )
printf("Message: %s", message);
close(fd[0]);
}
else{//parent: writer (reads from STDIN, sends data …Run Code Online (Sandbox Code Playgroud) 我在一个(愚蠢的)身份验证模块上找到了valgrind发现的这个奇怪的错误,它在堆分配上做了一些.
==8009== Invalid free() / delete / delete[] / realloc()
==8009== at 0x4C2A739: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8009== by 0x40263F: authenticate (server_utils.c:109)
==8009== by 0x401A27: main (server.c:240)
==8009== Address 0x51f1310 is 0 bytes inside a block of size 18 free'd
==8009== at 0x4C2A739: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8009== by 0x402633: authenticate (server_utils.c:108)
==8009== by 0x401A27: main (server.c:240)
=8009==
==8009== Invalid free() / delete / delete[] / realloc()
==8009== at 0x4C2A739: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==8009== by 0x40264B: authenticate (server_utils.c:110)
==8009== by 0x401A27: main …Run Code Online (Sandbox Code Playgroud) 我刚刚编写了一个算法,该算法在输入整数数组中找到具有最大/最小出现次数的值.我的想法是对数组进行排序(所有出现的顺序都是按顺序排列)并使用一<value:occurrences>对来为每个值存储相应的出现次数.
它应该是O(nlogn)复杂的,但我认为有一些常数乘数.我该怎么做才能提高性能?
#include <stdio.h>
#include <stdlib.h>
#include "e7_8.h"
#define N 20
/*Structure for <value, frequencies_count> pair*/
typedef struct {
int value;
int freq;
} VAL_FREQ;
void get_freq(int *v, int n, int *most_freq, int *less_freq) {
int v_i, vf_i, current_value, current_freq;
VAL_FREQ* sp = malloc(n*sizeof(VAL_FREQ));
if(sp == NULL) exit(EXIT_FAILURE);
mergesort(v,n);
vf_i = 0;
current_value = v[0];
current_freq = 1;
for(v_i=1; v_i<n+1; v_i++) {
if(v[v_i] == current_value) current_freq++;
else{
sp[vf_i].value = current_value;
sp[vf_i++].freq = current_freq;
current_value = v[v_i]; …Run Code Online (Sandbox Code Playgroud) 我有这个类存储int对:
static class IntPair {
int a; //JugsNode.a.content;
int b; //JugsNode.b.content;
public IntPair(int a, int b) {
this.a = a;
this.b = b;
}
}
Run Code Online (Sandbox Code Playgroud)
和一个定义如下的集合:
static HashSet<IntPair> confs = new HashSet<IntPair>();
Run Code Online (Sandbox Code Playgroud)
现在,它非常简单,我如何检查特定IntPair p对象是否已经包含在该集合中而没有任何引用但只有它的值?更清楚:
IntPair p = new Pair(0, 0);
confs.add(p);
IntPair p1 = new Pair(0, 0);
confs.contains(p1);
Run Code Online (Sandbox Code Playgroud)
显然这最后一次调用会返回false.那么,如何通过仅包含其值来检查该对是否包含在内.