Search Results

Search found 559 results on 23 pages for 'segmentation'.

Page 19/23 | < Previous Page | 15 16 17 18 19 20 21 22 23  | Next Page >

  • Passing Variable Length Arrays to a function

    - by David Bella
    I have a variable length array that I am trying to pass into a function. The function will shift the first value off and return it, and move the remaining values over to fill in the missing spot, putting, let's say, a -1 in the newly opened spot. I have no problem passing an array declared like so: int framelist[128]; shift(framelist); However, I would like to be able to use a VLA declared in this manner: int *framelist; framelist = malloc(size * sizeof(int)); shift(framelist); I can populate the arrays the same way outside the function call without issue, but as soon as I pass them into the shift function, the one declared in the first case works fine, but the one in the second case immediately gives a segmentation fault. Here is the code for the queue function, which doesn't do anything except try to grab the value from the first part of the array... int shift(int array[]) { int value = array[0]; return value; } Any ideas why it won't accept the VLA? I'm still new to C, so if I am doing something fundamentally wrong, let me know.

    Read the article

  • GCC/X86, Problems with relative jumps

    - by Ian Kelly
    I'm trying to do a relative jump in x86 assembly, however I can not get it to work. It seems that for some reason my jump keeps getting rewritten as an absolute jump or something. A simple example program for what I'm trying to do is this: .global main main: jmp 0x4 ret Since the jmp instruction is 4 bytes long and a relative jump is offset from the address of the jump + 1, this should be a fancy no-op. However, compiling and running this code will cause a segmentation fault. The real puzzler for me is that compiling it to the object level and then disassembling the object file shows that it looks like the assembler is correctly doing a relative jump, but after the file gets compiled the linker is changing it into another type of jump. For example if the above code was in a file called asmtest.s: $gcc -c asmtest.s $objdump -D asmtest.o ... Some info from objdump 00000000 <main>: 0: e9 00 00 00 00 jmp 5 <main+0x5> 5: c3 ret This looks like the assembler correctly made a relative jump, although it's suspicious that the jmp instruction is filled with 0s. I then used gcc to link it then disassembled it and got this: $gcc -o asmtest asmtest.o $objdump -d asmtest ...Extra info and other disassembled functions 08048394 <main>: 8048394: e9 6b 7c fb f7 jmp 4 <_init-0x8048274> 8048399: c3 ret This to me looks like the linker rewrote the jmp statement, or substituted the 5 in for another address. So my question comes down to, what am I doing wrong? Am I specifying the offset incorrectly? Am I misunderstanding how relative jumps work? Is gcc trying to make sure I don't do dangerous things in my code?

    Read the article

  • is it possible to turn off vdso on glibc side?

    - by heroxbd
    I am aware that passing vdso=0 to kernel can turn this feature off, and that the dynamic linker in glibc can automatic detect and use vdso feature from kernel. Here I met with this problem. There is a RHEL 5.6 box (kernel 2.6.18-238.el5) in my institution where I only have a normal user access, probably suffering from RHEL bug 673616. As I compile a toolchain of linux-headers-3.9/gcc-4.7.2/glibc-2.17/binutils-2.23 on top of it, gcc bootstrap fails in cc1 in stage2 cannnot be run Program received signal SIGSEGV, Segmentation fault. 0x00002aaaaaaca6eb in ?? () (gdb) info sharedlibrary From To Syms Read Shared Object Library 0x00002aaaaaaabba0 0x00002aaaaaac3249 Yes (*) /home/benda/gnto/lib64/ld-linux-x86-64.so.2 0x00002aaaaacd29b0 0x00002aaaaace2480 Yes (*) /home/benda/gnto/usr/lib/libmpc.so.3 0x00002aaaaaef2cd0 0x00002aaaaaf36c08 Yes (*) /home/benda/gnto/usr/lib/libmpfr.so.4 0x00002aaaab14f280 0x00002aaaab19b658 Yes (*) /home/benda/gnto/usr/lib/libgmp.so.10 0x00002aaaab3b3060 0x00002aaaab3b3b50 Yes (*) /home/benda/gnto/lib/libdl.so.2 0x00002aaaab5b87b0 0x00002aaaab5c4bb0 Yes (*) /home/benda/gnto/usr/lib/libz.so.1 0x00002aaaab7d0e70 0x00002aaaab80f62c Yes (*) /home/benda/gnto/lib/libm.so.6 0x00002aaaaba70d40 0x00002aaaabb81aec Yes (*) /home/benda/gnto/lib/libc.so.6 (*): Shared library is missing debugging information. and a simple program #include <sys/time.h> #include <stdio.h> int main () { struct timeval tim; gettimeofday(&tim, NULL); return 0; } get segment fault in the same way if compiled against glibc-2.17 and xgcc from stage1. Both cc1 and the test program can be run on another running RHEL 5.5 (kernel 2.6.18-194.26.1.el5) with gcc-4.7.2/glibc-2.17/binutils-2.23 as normal user. I cannot simply upgrade the box to a newer RHEL version, nor could I turn VDSO off via sysctl or proc. The question is, is there a way to compile glibc so that it turns off VDSO unconditionally?

    Read the article

  • Fatal error when using FILE* in Windows from DLL

    - by AlannY
    Hi there. Recently, I found a problem with Visual C++ 2008 compiler, but using minor hack avoid it. Currently, I cannot use the same hack, but problem exists as in 2008 as in 2010 (Express). So, I've prepared for you 2 simple C file: one for DLL, one for program: DLL (file-dll.c): #include <stdio.h> __declspec(dllexport) void print_to_stream (FILE *stream) { fprintf (stream, "OK!\n"); } And for program, which links this DLL via file-dll.lib: Program: #include <stdio.h> __declspec(dllimport) void print_to_stream (FILE *stream); int main (void) { print_to_stream (stdout); return 0; } To compile and link DLL: cl /LD file-dll.c To compile and link program: cl file-test.c file-dll.lib When invoking file-test.exe, I got the fatal error (similar to segmentation fault in UNIX). As I said early, I had that the same problem before: about transferring FILE* pointer to DLL. I thought, that it may be because of compiler mismatch, but now I'm using one compiler for everything and it's not the problem. ;-( What can I do now? UPD: I've found solution: cl /LD /MD file-dll.c cl /MD file-test.c file-dll.lib The key is to link to dynamic library, but (I did not know it) by default it links staticaly and (hencefore) error occurs (I see why). P.S. Thanks for patience.

    Read the article

  • Declaration, allocation and assignment of an array of pointers to function pointers

    - by manneorama
    Hello Stack Overflow! This is my first post, so please be gentle. I've been playing around with C from time to time in the past. Now I've gotten to the point where I've started a real project (a 2D graphics engine using SDL, but that's irrelevant for the question), to be able to say that I have some real C experience. Yesterday, while working on the event system, I ran into a problem which I couldn't solve. There's this typedef, //the void parameter is really an SDL_Event*. //but that is irrelevant for this question. typedef void (*event_callback)(void); which specifies the signature of a function to be called on engine events. I want to be able to support multiple event_callbacks, so an array of these callbacks would be an idea, but do not want to limit the amount of callbacks, so I need some sort of dynamic allocation. This is where the problem arose. My first attempt went like this: //initial size of callback vector static const int initial_vecsize = 32; //our event callback vector static event_callback* vec = 0; //size static unsigned int vecsize = 0; void register_event_callback(event_callback func) { if (!vec) __engine_allocate_vec(vec); vec[vecsize++] = func; //error here! } static void __engine_allocate_vec(engine_callback* vec) { vec = (engine_callback*) malloc(sizeof(engine_callback*) * initial_vecsize); } First of all, I have omitted some error checking as well as the code that reallocates the callback vector when the number of callbacks exceed the vector size. However, when I run this code, the program crashes as described in the code. I'm guessing segmentation fault but I can't be sure since no output is given. I'm also guessing that the error comes from a somewhat flawed understanding on how to declare and allocate an array of pointers to function pointers. Please Stack Overflow, guide me.

    Read the article

  • Implementing eval and load functions inside a scripting engine with Flex and Bison.

    - by Simone Margaritelli
    Hy guys, i'm developing a scripting engine with flex and bison and now i'm implementing the eval and load functions for this language. Just to give you an example, the syntax is like : import std.*; load( "some_script.hy" ); eval( "foo = 123;" ); println( foo ); So, in my lexer i've implemented the function : void hyb_parse_string( const char *str ){ extern int yyparse(void); YY_BUFFER_STATE prev, next; /* * Save current buffer. */ prev = YY_CURRENT_BUFFER; /* * yy_scan_string will call yy_switch_to_buffer. */ next = yy_scan_string( str ); /* * Do actual parsing (yyparse calls yylex). */ yyparse(); /* * Restore previous buffer. */ yy_switch_to_buffer(prev); } But it does not seem to work. Well, it does but when the string (loaded from a file or directly evaluated) is finished, i get a sigsegv : Program received signal SIGSEGV, Segmentation fault. 0xb7f2b801 in yylex () at src/lexer.cpp:1658 1658 if ( YY_CURRENT_BUFFER_LVALUE->yy_buffer_status == YY_BUFFER_NEW ) As you may notice, the sigsegv is generated by the flex/bison code, not mine ... any hints, or at least any example on how to implement those kind of functions? PS: I've succesfully implemented the include directive, but i need eval and load to work not at parsing time but execution time (kind of PHP's include/require directives).

    Read the article

  • Problem with setjmp/longjmp

    - by user294732
    The code below is just not working. Can anybody point out why #define STACK_SIZE 1524 static void mt_allocate_stack(struct thread_struct *mythrd) { unsigned int sp = 0; void *stck; stck = (void *)malloc(STACK_SIZE); sp = (unsigned int)&((stck)); sp = sp + STACK_SIZE; while((sp % 8) != 0) sp--; #ifdef linux (mythrd->saved_state[0]).__jmpbuf[JB_BP] = (int)sp; (mythrd->saved_state[0]).__jmpbuf[JB_SP] = (int)sp-500; #endif } void mt_sched() { fprintf(stdout,"\n Inside the mt_sched"); fflush(stdout); if ( current_thread->state == NEW ) { if ( setjmp(current_thread->saved_state) == 0 ) { mt_allocate_stack(current_thread); fprintf(stdout,"\n Jumping to thread = %u",current_thread->thread_id); fflush(stdout); longjmp(current_thread->saved_state, 2); } else { new_fns(); } } } All I am trying to do is to run the new_fns() on a new stack. But is is showing segmentation fault at new_fns(). Can anybody point me out what's wrong.

    Read the article

  • Private member vector of vector dynamic memory allocation

    - by Geoffroy
    Hello, I'm new to C++ (I learned programming with Fortran), and I would like to allocate dynamically the memory for a multidimensional table. This table is a private member variable : class theclass{ public: void setdim(void); private: std::vector < std::vector <int> > thetable; } I would like to set the dimension of thetable with the function setdim(). void theclass::setdim(void){ this->thetable.assign(1000,std::vector <int> (2000)); } I have no problem compiling this program, but as I execute it, I've got a segmentation fault. The strange thing for me is that this piece (see under) of code does exactly what I want, except that it doesn't uses the private member variable of my class : std::vector < std::vector < int > > thetable; thetable.assign(1000,std::vector <int> (2000)); By the way, I have no trouble if thetable is a 1D vector. In theclass : std::vector < int > thetable; and if in setdim : this->thetable.assign(1000,2); So my question is : why is there such a difference with "assign" between thetable and this-thetable for a 2D vector? And how should I do to do what I want? Thank-you for your help, Best regards, -- Geoffroy

    Read the article

  • Hashtable resizing leaks memory

    - by thpetrus
    I wrote a hashtable and it basically consists of these two structures: typedef struct dictEntry { void *key; void *value; struct dictEntry *next; } dictEntry; typedef struct dict { dictEntry **table; unsigned long size; unsigned long items; } dict; dict.table is a multidimensional array, which contains all the stored key/value pair, which again are a linked list. If half of the hashtable is full, I expand it by doubling the size and rehashing it: dict *_dictRehash(dict *d) { int i; dict *_d; dictEntry *dit; _d = dictCreate(d->size * 2); for (i = 0; i < d->size; i++) { for (dit = d->table[i]; dit != NULL; dit = dit->next) { _dictAddRaw(_d, dit); } } /* FIXME memory leak because the old dict can never be freed */ free(d); // seg fault return _d; } The function above uses the pointers from the old hash table and stores it in the newly created one. When freeing the old dict d a Segmentation Fault occurs. How am I able to free the old hashtable struct without having to allocate the memory for the key/value pairs again?

    Read the article

  • Problem with writing mobilesubstrate plugins for iOS

    - by overboming
    I am trying to hooking message sending for iOS 3.2, I implement my own hook on a working ExampleHook program I find on the web. But my hook apparently caused segmentation fault everytime it hooks and I don't know why. I want to hook to [NSURL initWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL; and here is my related implementation static id __$GFWInterceptor_NSURL_initWithString2(NSURL<GFWInterceptor> *_NSURL, NSString *URLString, NSURL* baseURL){ NSLog(@"We have intercepted this url: %@",URLString); [_NSURL __HelloNSURL_initWithString:URLString relativeToURL:baseURL]; establish hook Class _$NSURL = objc_getClass("NSURL"); MSHookMessage(_$NSURL, @selector(initWithString:relativeToURL:), (IMP) &__$GFWInterceptor_NSURL_initWithString2, "__HelloNSURL_"); original method declaration - (void)__HelloNSURL_initWithString:(NSString *)URLString relativeToURL:(NSURL *)baseURL; and here is my gdb backtrace Program received signal EXC_BAD_ACCESS, Could not access memory. Reason: KERN_INVALID_ADDRESS at address: 0x74696e71 0x335625f8 in objc_msgSend () (gdb) bt 0 0x335625f8 in objc_msgSend () 1 0x32c05b1a in CFStringGetLength () 2 0x32c108a8 in _CFStringIsLegalURLString () 3 0x32b1c32a in -[NSURL initWithString:relativeToURL:] () 4 0x000877c0 in __$GFWInterceptor_NSURL_initWithString2 () 5 0x32b1c220 in +[NSURL URLWithString:relativeToURL:] () 6 0x32b1c1f4 in +[NSURL URLWithString:] () 7 0x3061c614 in createUniqueWebDataURL () 8 0x3061c212 in +[WebFrame(WebInternal) _createMainFrameWithSimpleHTMLDocumentWithPage:frameView:withStyle:editable:] () and apparently it hooks, but there is some memory issue there and I can't find anything to blame now

    Read the article

  • What could cause these Apache crash errors ?

    - by jacobanderssen
    Hello guys. I had a server crash several days ago. I use Cacti to keep stats: at the time when the server crashed, a huge spike from Load 1 to Load 200 occurred, with over 800 processes in the run queue ( from 300 average). Upon checking /var/log/httpd I notice this: * glibc detected /usr/sbin/httpd: double free or corruption (out): 0x00002b8f3142c2f0 ** Followed by alot of these: [Sat Mar 13 19:20:20 2010] [warn] child process 3090 still did not exit, sending a SIGTERM [Sat Mar 13 19:20:20 2010] [warn] child process 3091 still did not exit, sending a SIGTERM Followed by this: ======= Backtrace: ========= /lib64/libc.so.6[0x2b8f1463c2ef] /lib64/libc.so.6(cfree+0x4b)[0x2b8f1463c73b] /usr/lib64/libapr-1.so.0(apr_pool_destroy+0x131)[0x2b8f13f98821] /usr/sbin/httpd[0x2b8f126df47e] /usr/sbin/httpd[0x2b8f126df4ab] /lib64/libpthread.so.0[0x2b8f141b87c0] /etc/httpd/modules/mod_file_cache.so[0x2b8f1cdf00fb] ======= Memory map: ======== And finally a lot of these: [Sat Mar 13 19:20:27 2010] [error] could not make child process 733 exit, attempting to continue anyway [Sat Mar 13 19:20:27 2010] [error] could not make child process 24560 exit, attempting to continue anyway [Sat Mar 13 19:20:27 2010] [error] could not make child process 31384 exit, attempting to continue anyway I am also noticing one or two lines like this: [Mon Mar 15 01:17:26 2010] [notice] child pid 20765 exit signal Segmentation fault (11) Please help me shed some light on this. Thanks !

    Read the article

  • Boost multi_index_container crash in release mode

    - by Zan Lynx
    I have a program that I just changed to using a boost::multi_index_container collection. After I did that and tested my code in debug mode, I was feeling pretty good about myself. However, then I compiled a release build with NDEBUG set, and the code crashed. Not immediately, but sometimes in single-threaded tests and often in multi-threaded tests. The segmentation faults happen deep inside boost insert and rotate functions related to the index updates and they are happening because a node has NULL left and right pointers. My code looks a bit like this: struct Implementation { typedef std::pair<uint32_t, uint32_t> update_pair_type; struct watch {}; struct update {}; typedef boost::multi_index_container< update_pair_type, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag<watch>, boost::multi_index::member<update_pair_type, uint32_t, &update_pair_type::first> >, boost::multi_index::ordered_non_unique< boost::multi_index::tag<update>, boost::multi_index::member<update_pair_type, uint32_t, &update_pair_type::second> > > > update_map_type; typedef std::vector< update_pair_type > update_list_type; update_map_type update_map; update_map_type::iterator update_hint; void register_update(uint32_t watch, uint32_t update); void do_updates(uint32_t start, uint32_t end); }; void Implementation::register_update(uint32_t watch, uint32_t update) { update_pair_type new_pair( watch_offset, update_offset ); update_hint = update_map.insert(update_hint, new_pair); if( update_hint->second != update_offset ) { bool replaced _unused_ = update_map.replace(update_hint, new_pair); assert(replaced); } }

    Read the article

  • How to return array of C++ objects from a PHP extension

    - by John Factorial
    I need to have my PHP extension return an array of objects, but I can't seem to figure out how to do this. I have a Graph object written in C++. Graph.getNodes() returns a std::map<int, Node*>. Here's the code I have currently: struct node_object { zend_object std; Node *node; }; zend_class_entry *node_ce; then PHP_METHOD(Graph, getNodes) { Graph *graph; GET_GRAPH(graph, obj) // a macro I wrote to populate graph node_object* n; zval* node_zval; if (obj == NULL) { RETURN_NULL(); } if (object_init_ex(node_zval, node_ce) != SUCCESS) { RETURN_NULL(); } std::map nodes = graph-getNodes(); array_init(return_value); for (std::map::iterator i = nodes.begin(); i != nodes.end(); ++i) { php_printf("X"); n = (node_object*) zend_object_store_get_object(node_zval TSRMLS_CC); n-node = i-second; add_index_zval(return_value, i-first, node_zval); } php_printf("]"); } When i run php -r '$g = new Graph(); $g->getNodes();' I get the output XX]Segmentation fault meaning the getNodes() function loops successfully through my 2-node list, returns, then segfaults. What am I doing wrong?

    Read the article

  • How can I modified the value of a string defined in a struc?

    - by Eric
    Hi, I have the following code in c++: define TAM 4000 define NUMPAGS 512 struct pagina { bitset<12 direccion; char operacion; char permiso; string *dato; int numero; }; void crearPagina(pagina* pag[], int pos, int dir) { pagina * paginas = (pagina*)malloc(sizeof(char) * TAM); paginas - direccion = bitset<12 (dir); paginas - operacion = 'n'; paginas - permiso = 'n'; string **tempDato = &paginas - dato; char *temp = " "; **tempDato = temp; paginas - numero = 0; pag[pos] = paginas; } I want to modify the value of the variable called "string *dato" in the struct pagina but, everytime I want to assing a new value, the compiler throws a segmentation fault. In this case I'm using a pointer to string, but I have also tried with a string. In a few words I want to do the following: pagina - dato = "test"; Any idea? Thanks in advance!!!

    Read the article

  • display multiple errors via bool flag c++

    - by igor
    Been a long night, but stuck on this and now am getting "segmentation fault" in my compiler.. Basically I'm trying to display all the errors (the cout) needed. If there is more than one error, I am to display all of them. bool validMove(const Square board[BOARD_SIZE][BOARD_SIZE], int x, int y, int value) { int index; bool moveError = true; const int row_conflict(0), column_conflict(1), grid_conflict(2); int v_subgrid=x/3; int h_subgrid=y/3; getCoords(x,y); for(index=0;index<9;index++) if(board[x][index].number==value){ cout<<"That value is in conflict in this row\n"; moveError=false; } for(index=0;index<9;index++) if(board[index][y].number==value){ cout<<"That value is in conflict in this column\n"; moveError=false; } for(int i=v_subgrid*3;i<(v_subgrid*3 +3);i++){ for(int j=h_subgrid*3;j<(h_subgrid*3+3);j++){ if(board[i][j].number==value){ cout<<"That value is in conflict in this subgrid\n"; moveError=false; } } } return true; }

    Read the article

  • OpenMP in Fortran

    - by user345293
    I very rarely use fortran, however I have been tasked with taking legacy code rewriting it to run in parallel. I'm using gfortran for my compiler choice. I found some excellent resources at https://computing.llnl.gov/tutorials/openMP/ as well as a few others. My problem is this, before I add any OpenMP directives, if I simply compile the legacy program: gfortran Example1.F90 -o Example1 everything works, but turning on the openmp compiler option even without adding directives: gfortran -openmp Example1.F90 -o Example1 ends up with a Segmentation fault when I run the legacy program. Using smaller test programs that I wrote, I've successfully compiled other programs with -openmp that run on multiple threads, but I'm rather at a loss why enabling the option alone and no directives is resulting in a seg fault. I apologize if my question is rather simple. I could post code but it is rather long. It faults as I assign initial values: REAL, DIMENSION(da,da) :: uconsold REAL, DIMENSION(da,da,dr,dk) :: uconsolde ... uconsold=0.0 uconsolde=0.0 The first assignment to "uconsold" works fine, the second seems to be the source of the fault as when I comment the line out the next several lines execute merrily until "uconsolde" is used again. Thank you for any help in this matter.

    Read the article

  • c programming malloc question

    - by user535256
    Hello guys, Just got query regarding c malloc() function. I am read()ing x number of bytes from a file to get lenght of filename, like ' read(file, &namelen, sizeof(unsigned char)); ' . The variable namelen is a type unsigned char and was written into file as that type (1 byte). Now namelen has the lenght of filename ie namelen=8 if file name was 'data.txt', plus extra /0 at end, that working fine. Now I have a structure recording file info, ie filename, filelenght, content size etc. struct fileinfo { char *name; ...... other variable like size etc }; struct fileinfo *files; Question: I want to make that files.name variable the size of namelen ie 8 so I can successfully write the filename into it, like ' files[i].name = malloc(namelen) ' However, I dont want it to be malloc(sizeof(namelen)) as that would make it file.name[1] as the size of its type unsigned char. I want it to be the value thats stored inside variable &namelen ie 8 so file.name[8] so data.txt can be read() from file as 8 bytes and written straight into file.name[8? Is there a way to do this my current code is this and returns 4 not 8 files[i].name = malloc(namelen); //strlen(files[i].name) - returns 4 //perhaps something like malloc(sizeof(&namelen)) but does not work Thanks for any suggestions Have tried suggested suggestions guys, but I now get a segmentation fault error using: printf("\nsizeofnamelen=%x\n",namelen); //gives 8 for data.txt files[i].name = malloc(namelen + 1); read(file, &files[i].name, namelen); int len=strlen(files[i].name); printf("\nnamelen=%d",len); printf("\nname=%s\n",files[i].name); When I try to open() file with that files[i].name variable it wont open so the data does not appear to be getting written inside the read() &files[i].name and strlen() causes segemntation error as well as trying to print the filename

    Read the article

  • pointer to a structure in a nested structure

    - by dpka6
    I have a 6 levels of nested structures. I am having problem with last three levels. The program compiles fine but when I run it crashes with Segmentation fault. There is some problem in assignment is what I feel. Kindly point out the error. typedef struct { char addr[6]; int32_t rs; uint16_t ch; uint8_t ap; } C; typedef struct { C *ap_info; } B; typedef struct { union { B wi; } u; } A; function1(char addr , int32_t rs, uint16_t ch, uint8_t ap){ A la; la.u.wi.ap_info->addr[6] = addr; la.u.wi.ap_info->rs = rs; la.u.wi.ap_info->ch = ch; la.u.wi.ap_info->ap = ap; }

    Read the article

  • What is the best way to do scoped finds based on access control rules in Rails?

    - by Rafael Szuminski
    Hi I need to find an elegant solution to scoped finds based on access control rules. Essentially I have the following setup: Users Customers AccessControl - Defines which user has access to another users data Users need to be able to access not just their own customers but also shared customers of other users. Obviously something like a simple association will not work: has_many :customers and neither will this: has_many :customers, :conditions => 'user_id in (1,2,3,4,5)' because the association uses with_scope and the added condition is an AND condition not an OR condition. I also tried overriding the find and method_missing methods with the association extension like this: has_many :customers do def find(*args) #get the user_id and retrieve access conditions based on the id #do a find based on the access conditions and passed args end def method_missing(*args) #get the user_id and retrieve access conditions based on the id #do a find based on the access conditions and passed args end end but the issue is that I don't have access to the user object / parent object inside the extension methods and it just does not work as planned. I also tried default_scope but as posted here before you can't pass a block to a default scope. Anyhow, I know that data segmentation and data access controls have been done before using rails and am wondering if somebody found an elegant way to do it. UPDATE: The AccessControl table has the following layout user_id shared_user_id The customer table has this structure: id account_id user_id first_name last_name Assuming the the following data would be in the AccessControl table: 1 1 1 3 1 4 2 2 2 13 and so on... And the account_id for user 1 is 13 I need to be able to retrieve customers that can be best described with the following sql statement: select * from customers where (account_id = 13 and user_id = null) or (user_id in (1,3,4))

    Read the article

  • visual analysis of web pages in ruby

    - by Clint Miller
    I'm looking to write some code that does visual analysis of web pages, preferably using Ruby. My code will need to be able to determine the top, left, width, height, background color, color, and font size for all the elements in the DOM. Of course, these values can only be calculated once all CSS is applied. So, I don't think that Nokogiri is up for the job. Ultimately, I'm trying to use this data in a VIPS-like (Vision-Based Page Segmentation) algorithm in an attempt to find the main content in downloaded news articles. I've considered using Watir to drive Chrome or Firefox and then extract the data. The problem is that browsers can't be run headless through Watir (I think). Ultimately, this code will be running on an array of Linux servers in a data center. So, the code won't have easy access to an X Server for displaying the browser. I suppose one solution is to use Watir and run a headless X Server on the Linux servers. That's a bit of a pain, but it looks like my best option right now. Does anyone have any better ideas?

    Read the article

  • How can I modify the value of a string defined in a struct?

    - by Eric
    Hi, I have the following code in c++: #define TAM 4000 #define NUMPAGS 512 struct pagina { bitset<12> direccion; char operacion; char permiso; string *dato; int numero; }; void crearPagina(pagina* pag[], int pos, int dir) { pagina * paginas = (pagina*)malloc(sizeof(char) * TAM); paginas -> direccion = bitset<12> (dir); paginas -> operacion = 'n'; paginas -> permiso = 'n'; string **tempDato = &paginas -> dato; char *temp = " "; **tempDato = temp; paginas -> numero = 0; pag[pos] = paginas; } I want to modify the value of the variable called "string *dato" in the struct pagina but, everytime I want to assing a new value, the compiler throws a segmentation fault. In this case I'm using a pointer to string, but I have also tried with a string. In a few words I want to do the following: pagina - dato = "test"; Any idea? Thanks in advance!!!

    Read the article

  • Question on passing a pointer to a structure in C to a function?

    - by worlds-apart89
    Below, I wrote a primitive singly linked list in C. Function "addEditNode" MUST receive a pointer by value, which, I am guessing, means we can edit the data of the pointer but can not point it to something else. If I allocate memory using malloc in "addEditNode", when the function returns, can I see the contents of first-next ? Second question is do I have to free first-next or is it only first that I should free? I am running into segmentation faults on Linux. #include <stdio.h> #include <stdlib.h> typedef struct list_node list_node_t; struct list_node { int value; list_node_t *next; }; void addEditNode(list_node_t *node) { node->value = 10; node->next = (list_node_t*) malloc(sizeof(list_node_t)); node->next->value = 1; node->next->next = NULL; } int main() { list_node_t *first = (list_node_t*) malloc(sizeof(list_node_t)); first->value = 1; first->next = NULL; addEditNode(first); free(first); return 0; }

    Read the article

  • short-cutting equality checking in F#?

    - by John Clements
    In F#, the equality operator (=) is generally extensional, rather than intensional. That's great! Unfortunately, it appears to me that F# does not use pointer equality to short-cut these extensional comparisons. For instance, this code: type Z = MT | NMT of Z ref // create a Z: let a = ref MT // make it point to itself: a := NMT a // check to see whether it's equal to itself: printf "a = a: %A\n" (a = a) ... gives me a big fat segmentation fault[*], despite the fact that 'a' and 'a' both evaluate to the same reference. That's not so great. Other functional languages (e.g. PLT Scheme) get this right, using pointer comparisons conservatively, to return 'true' when it can be determined using a pointer comparison. So: I'll accept the fact that F#'s equality operator doesn't use short-cutting; is there some way to perform an intensional (pointer-based) equality check? The (==) operator is not defined on my types, and I'd love it if someone could tell me that it's available somehow. Or tell me that I'm wrong in my analysis of the situation: I'd love that, too... [*] That would probably be a stack overflow on Windows; there are things about Mono that I'm not that fond of...

    Read the article

  • Two dimensional strings in C++

    - by dada
    I want to write something like 2d strings in C++. I tried with : vector< vector<string> > table; int m,n,i,j; string s; cin>>n>>m; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cin>>s; table[i][j] = s; } } cout << "\n\n\n\n"; for(i=0;i<n;i++) { for(j=0;j<m;j++) { cout<<table[i][j]<<" "; } cout<<"\n"; } no compile errors, but when i enter input like: 10 20 .....#.............. .....#.............. .....#.............. .....#.............. ######.............. .......###.......... .......#.#.......... .......###...####### .............#.....# .............####### It gives me segmentation fault. Why ? What's wrong ? And how it should be done so it would work correctly ? Thank you.

    Read the article

  • Adding and sorting a linked list in C

    - by user1202963
    In my assignment, I have to write a function that takes as arguments a pointer to a "LNode" structure and an integer argument. Then, I have to not only add that integer into the linked list, but also put place it so that the list is in proper ascending order. I've tried several various attempts at this, and this is my code as of posting. LNode* AddItem(LNode *headPtr, int newItem) { auto LNode *ptr = headPtr; ptr = malloc(sizeof(LNode)); if (headPtr == NULL) { ptr->value = newItem; ptr->next = headPtr; return ptr; } else { while (headPtr->value > newItem || ptr->next != NULL) { printf("While\n"); // This is simply to let me know how many times the loop runs headPtr = headPtr->next; } ptr->value = newItem; ptr->next = headPtr; return ptr; } } // end of "AddItem" When I run it, and try to insert say a 5 and then a 3, the 5 gets inserted, but then the while loop runs once and I get a segmentation fault. Also I cannot change the arguments as it's part of a skeletal code for this project. Thanks to anyone who can help. If it helps this is what the structure looks like typedef struct LNode { int value; struct LNode *next; } LNode;

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23  | Next Page >